gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 03:34:44 25 4
gpt4 key购买 nike

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 ofdeclarations into the declarative region in which theusing-declaration appears. The set of declarations introduced by theusing-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 aconstructor, the unqualified-id is declared in the declarative regionin which the using-declaration appears as a synonym for eachdeclaration introduced by the using-declarator. [ Note: Only thespecified name is so declared; specifying an enumeration name in ausing-declaration does not declare its enumerators in theusing-declaration’s declarative region. — end note ] If theusing-declarator names a constructor, it declares that the classinherits the set of constructor declarations introduced by theusing-declarator from the nominated base class.

请注意 factory method按预期工作。

编辑:它已经被问过并且answered ;)

关于c++ - 关于默认可构造性的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70095977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com