c++ - 关于默认可构造性的差异

标签 c++ c++20

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

Live example


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/

相关文章:

c++ - 将右值参数传递给非常量左值引用的参数

c++ - 可以指定 C++20 模板化 lambda 来推断嵌套在参数中的类型吗?

C++ 函数模板重载 : empty braces vs explicit int

c++ - C++20 标准对使用子对象作为模板非类型参数有什么看法?

c++ - 在 Linux 上以编程方式设置 DNS 名称服务器

c++ - 网格三角剖分和简化 C++ 库

c# - 如何通过变量查找分配的内存?

c++ - 如何设置理想的 QPixmapCache::cacheLimit?

c++ - 为什么聚合推导中不支持大括号初始化列表但支持大括号省略?

模块中的 C++ "Using"