不同的编译器在编译以下代码时表现不同:(点此查看)
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++: successful compilation
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: successful compilation
哪种编译器行为符合标准?
附加信息: