【发布时间】:2018-05-09 10:46:41
【问题描述】:
不同的编译器show different behavior编译如下代码:
namespace N
{
namespace Foo
{
template <typename>
struct Foo
{
};
}
}
template <typename Type>
using Foo = N::Foo::Foo<Type>;
namespace N
{
template <typename Type>
struct Bar : Foo<Type>
{
};
}
int main()
{
}
经过测试的编译器及其编译标志:
-
clang++ 5.0.0:
-std=c++14 -Wall -Wextra -Werror -pedantic-errors -
g++ 7.2:
-std=c++14 -Wall -Wextra -Werror -pedantic-errors -
vc++ 19.10.25017(VS 2017):
/EHsc /Za /std:c++14 /permissive- -
icc 18.0.0:
-std=c++14 -Wall -Werror
编译结果:
-
clang++:
18 : <source>:18:15: error: expected class name struct Bar : Foo ^ g++:编译成功
-
vc++:
18 : <source>(18): error C2516: 'Foo': is not a legal base class 13 : <source>(13): note: see declaration of 'Foo' 20 : <source>(20): note: see reference to class template instantiation 'N::Bar<Type>' being compiled 18 : <source>(18): error C2143: syntax error: missing ',' before '<' icc:编译成功
哪种编译器行为符合标准?
附加信息:
【问题讨论】:
标签: c++ templates namespaces c++14 language-lawyer