我偶然发现了一个错误,它只出现在GCC 6.2.0上,而不是出现在Clang 3.9.0上(都在-std=c++14模式下).我不确定哪种行为是正确的(以及我是否应该提交错误).
这是代码:
template<typename type_t>
class foo_t
{
};
class bar_t
{
public:
using foo_t = int;
};
class baz_t:
public bar_t
{
private:
template<typename type_t>
friend class foo_t;
};
Run Code Online (Sandbox Code Playgroud)
在GCC上,这会出现以下错误:
test.cpp:17:15: error: using typedef-name ‘using foo_t = int’ after ‘class’
friend class foo_t;
^~~~~
test.cpp:9:19: note: ‘using foo_t = int’ has a previous declaration here
using foo_t = int;
^
Run Code Online (Sandbox Code Playgroud)
根据我所知的C++标准,父级typedef(或usings)不应泄漏到子级的范围内,您需要明确限定名称:例如,请参阅将"typedef"从基于"模板"的派生类传播到"模板".所以在我看来,GCC在这里是不正确的,但我不太确定我的C++知识可以自信地说.
谢谢你的帮助!