OSDN Git Service

cp:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / parse / error11.C
1 // { dg-do compile }
2 // Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
3 // Try to find out when the digraph '<:' is used as a mistake, and parse it
4 //  correctly to avoid cascaded errors.
5
6 struct B;
7
8 template <class A>
9 struct Foo 
10 {
11   template <class T>
12   struct Nested
13   {
14     static void method(void) {}
15   };
16
17   void method(void) {
18     typename Foo<::B>::template Nested<::B> n; // { dg-error "cannot begin|alternate spelling" }
19     n.template Nested<B>::method();
20     n.template Nested<::B>::method();  // { dg-error "cannot begin|alternate spelling" }
21     Nested<B>::method();
22     Nested<::B>::method(); // { dg-error "cannot begin|alternate spelling" }
23   }
24 };
25
26 template <int N> struct Foo2 {};
27 template struct Foo2<::B>;  // { dg-error "cannot begin|alternate spelling|type/value mismatch|expected a constant" }
28
29 int value = 0;
30
31 void func(void)
32 {
33   Foo<::B> f; // { dg-error "cannot begin|alternate spelling" }
34   f.Foo<B>::method();
35   f.Foo<::B>::method(); // { dg-error "cannot begin|alternate spelling" }
36
37   // Check cases where we the token sequence is the correct one, but there
38   //  was no digraph or whitespaces in the middle, so we should not emit
39   //  the special error message.
40   Foo<: :B> k2;     // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" }
41   Foo[:B> k1;       // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" } 
42 // { dg-error "" "" { target *-*-* } 40 }
43 // { dg-error "" "" { target *-*-* } 41 }
44
45   int Foo[2];
46   Foo[::value] = 0;
47 }
48
49 template struct Foo<::B>; // { dg-error "cannot begin|alternate spelling" }
50
51 // On the first error message, an additional note about the use of 
52 //  -fpermissive should be present
53 // { dg-error "-fpermissive" "-fpermissive" { target *-*-* } 18 }