Вот упрощенный код:
Код: Выделить всё
template
void f() {
struct A{ struct B{}; };
// ok everywhere
auto b = typename A::B();
b = typename A::B{};
// ok in EDG and MSVC
b = A::B();
// ok in EDG only
b = A::B{};
}
int main() {
f();
}
- Все компиляторы принимают имя типа A::B.
- Построение объекта с помощью A::B() не нравится Clang и GCC, которые жалуются
Код: Выделить всё
error: missing 'typename' prior to dependent type name 'A::B'
error: dependent-name 'f()::A::B' is parsed as a non-type, but instantiation yields a type
- И только EDG принимает построение объектов с помощью A::B{, тогда как Clang, GCC и MSVC выводят аналогичные ошибки:
Код: Выделить всё
error: expected ';' after expression
error: expected ';' before '{' token [-Wtemplate-body]
error C2760: syntax error: '{' was unexpected here; expected 'expression'
Какая реализация здесь правильная?
Подробнее здесь: https://stackoverflow.com/questions/798 ... -templates