Clang 和 GCC 似乎不同意什么使类型默认可构造。 GCC在这里错了吗?标准的正式定义是不是对此没有明确说明?
#include <concepts>
class base {
protected:
base() = default;
};
struct der : base {
using base::base;
der(int) {}
};
der d; // constexpr base::base() is protected within this context
static_assert(std::semiregular<der>); // fails on GCC
JHBonarius 和 alagner 提供了所要求的信息,引用了已经很好地涵盖了细节的现有资源。现在,我认为最好将这个问题更多地指向 Clang 的偏离行为。我已经启动了错误报告流程,并将在此处发布任何跟进。
最佳答案
正如我们在评论中讨论的那样,GCC 似乎实现了标准权利(尽管这似乎违反直觉):
C++ 标准,10.3.3.2
Each using-declarator in a using-declaration introduces a set of declarations into the declarative region in which the using-declaration appears. The set of declarations introduced by the using-declarator is found by performing qualified name lookup (6.4.3, 13.2) for the name in the using-declarator, excluding functions that are hidden as described below. If the using-declarator does not name a constructor, the unqualified-id is declared in the declarative region in which the using-declaration appears as a synonym for each declaration introduced by the using-declarator. [ Note: Only the specified name is so declared; specifying an enumeration name in a using-declaration does not declare its enumerators in the using-declaration’s declarative region. — end note ] If the using-declarator names a constructor, it declares that the class inherits the set of constructor declarations introduced by the using-declarator from the nominated base class.
请注意 factory method按预期工作。
编辑:它已经被问过并且answered ;)
关于c++ - 关于默认可构造性的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70095977/