A
ag
gcc and Sun Studio do not allow this, why does Visual Studio?
template <class T> class foo { };
void f()
{
class bar { };
foo<bar> x;
}
C:\work>c:\mingw\bin\g++ -v
gcc version 3.4.2 (mingw-special)
c:\mingw\bin\g++ -c 12735.cpp
12735.cpp: In function `void f()':
12735.cpp:6: error: `f()::bar' uses local type `f()::bar'
12735.cpp:6: error: trying to instantiate `template<class T> class
foo'
12735.cpp:6: error: invalid type in declaration before ';' token
$ CC -V
CC: Sun C++ 5.5 2003/03/12
$ CC -c 12735.cpp
"12735.cpp", line 6: Error: The local type "bar" cannot be used as a
template argument.
1 Error(s) detected.
$ CC -V
CC: Sun C++ 5.7 2005/01/07
$ CC -c 12735.cpp
"12735.cpp", line 6: Error: The local type "bar" cannot be used as a
template argument.
C:\work>cl /c 12735.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
12735.cpp
C:\work>
template <class T> class foo { };
void f()
{
class bar { };
foo<bar> x;
}
C:\work>c:\mingw\bin\g++ -v
gcc version 3.4.2 (mingw-special)
c:\mingw\bin\g++ -c 12735.cpp
12735.cpp: In function `void f()':
12735.cpp:6: error: `f()::bar' uses local type `f()::bar'
12735.cpp:6: error: trying to instantiate `template<class T> class
foo'
12735.cpp:6: error: invalid type in declaration before ';' token
$ CC -V
CC: Sun C++ 5.5 2003/03/12
$ CC -c 12735.cpp
"12735.cpp", line 6: Error: The local type "bar" cannot be used as a
template argument.
1 Error(s) detected.
$ CC -V
CC: Sun C++ 5.7 2005/01/07
$ CC -c 12735.cpp
"12735.cpp", line 6: Error: The local type "bar" cannot be used as a
template argument.
C:\work>cl /c 12735.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
12735.cpp
C:\work>