【发布时间】:2021-07-09 18:53:33
【问题描述】:
考虑以下代码 sn-p 与 C++20 using-enum-declaration:
namespace A { enum A {}; };
using namespace A;
using enum A;
gcc-trunk rejects 它与:
<source>:4:12: error: reference to 'A' is ambiguous
4 | using enum A;
| ^
<source>:1:20: note: candidates are: 'enum A::A'
1 | namespace A { enum A {}; };
| ^
<source>:1:11: note: 'namespace A { }'
1 | namespace A { enum A {}; };
| ^
<source>:4:12: error: 'A' has not been declared
4 | using enum A;
| ^
但是,msvc 接受它。有趣的是,如果我为 enum A 添加命名空间限定符:
namespace A { enum A {}; };
using namespace A;
using enum A::A;
gcc 接受这一次,但 msvc rejects 它与:
<source>(4): error C2872: 'A': ambiguous symbol
<source>(1): note: could be 'A'
<source>(1): note: or 'A::A'
哪个编译器是正确的?
【问题讨论】:
标签: c++ language-lawyer c++20 name-lookup using-declaration