This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
G++ allows illegal template type arguments
- To: gcc-bugs at gcc dot gnu dot org
- Subject: G++ allows illegal template type arguments
- From: Hyman Rosen <hymie at jyacc dot com>
- Date: Wed, 25 Aug 1999 14:27:17 -0400
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.