question on instantiation of template argument with local scope

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top