------- Comment #1 from sebor at roguewave dot com 2006-05-10 01:07 -------
Here's a test case designed to exhaustively exercise all cases mentioned in
14.8.2, p2. Hope it helps.
$ cat ~/tmp/t.cpp && (c=1; while [ $c -lt 15 ]; do printf "%s: " "$c"; gcc
-DCASE=$c ~/tmp/t.cpp 2>/dev/null; if [ $? -eq 0 ]; then echo okay; else echo
ERROR; fi; c=`expr $c + 1`; done)
#if CASE == 1
// attempting to create an array with an element type that is void
template <class, class U = void> struct A { typedef U X [1]; };
#elif CASE == 2
// attempting to create an array with an element type that is function
template <class, class U = void ()> struct A { typedef U X [1]; };
#elif CASE == 3
// attempting to create an array with an element type that is a reference
template <class, class U = T&> struct A { typedef U X [1]; };
#elif CASE == 4
// attempting to create an array with size that is zero
template <class, int N = 0> struct A { typedef T X [N]; };
#elif CASE == 5
// attempting to create an array with size that is negative
template <class, int N = -1> struct A { typedef T X [N]; };
#elif CASE == 6
// attempting to use a type that is not a class type in a qualified name
template <class T> struct A { typedef typename T::X X; };
#elif CASE == 7
// attempting to use a non-existent member type
template <class T, class U = T> struct A { typedef typename A<U>::X X; };
#elif CASE == 8
// attempting to create a pointer to reference type
template <class T, class U = T&> struct A { typedef U* X; };
#elif CASE == 9
// attempting to create a reference to reference type
template <class T, class U = T&> struct A { typedef U& X; };
#elif CASE == 10
// attempting to create a reference to void type
template <class T, class U = void> struct A { typedef U& X; };
#elif CASE == 11
// attempting to create a pointer to member of T when T is not class type
template <class T> struct A { typedef int T::*X; };
#elif CASE == 12
// attempting to perform an invalid conversion
char ch;
template <class T, T* = &ch> struct A { typedef T X; };
#elif CASE == 13
// attempting to create a function type with a void parameter
template <class T, class U = void> struct A { typedef T X (U); };
#elif CASE == 14
// attempting to create a cv-qualified function type
template <class T, class U = void ()> struct A { typedef U& X; };
#else
# error CASE not #defined
#endif
template <class T> struct B { typedef T Y; };
template <class T>
A<T> foo (T);
template <class T>
B<T> foo (T) { return B<T>(); }
int main ()
{
foo (0);
}
The output of running the script with gcc 4.1:
1: ERROR
2: ERROR
3: ERROR
4: ERROR
5: ERROR
6: ERROR
7: ERROR
8: ERROR
9: ERROR
10: ERROR
11: ERROR
12: okay
13: ERROR
14: ERROR
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27527