This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

G++ allows illegal template type arguments


14.3.1¶2 [temp.arg.type] in the C++ Standard says that (among other
things) an unnamed type may not be used as a template type argument.
Even with maximum pedanticness, g++ compiles the following code
silently:

#include <iostream>

enum { a };

struct
{
	operator int() const { return 0; }
} b;

template <typename T>
void f(T v)
{
	std::cout << v << std::endl;
	// std::cout += v;
}

int main()
{
	f(a);
	f(b);
}

If you uncomment the commented line, g++ will complain

 In function `void f<{anonymous enum}>({anonymous enum})':
19:   instantiated from here
14: no match for `_IO_ostream_withassign & += {anonymous enum} &'
 In function `void f<{anonymous struct}>({anonymous struct})':
20:   instantiated from here
14: no match for `_IO_ostream_withassign & += {anonymous struct} &'

so it knows that anonymous types have been used.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]