aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/parse/error11.C
blob: 0a8e2e4fc3d64b53ae589d11d4ff6071b008c659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// { dg-do compile }
// Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
// Try to find out when the digraph '<:' is used as a mistake, and parse it
//  correctly to avoid cascaded errors.

struct B;

template <class A>
struct Foo 
{
  template <class T>
  struct Nested
  {
    static void method(void) {}
  };

  void method(void) {
    typename Foo<::B>::template Nested<::B> n; // { dg-error "cannot begin|alternate spelling" }
    n.template Nested<B>::method();
    n.template Nested<::B>::method();  // { dg-error "cannot begin|alternate spelling" }
    Nested<B>::method();
    Nested<::B>::method(); // { dg-error "cannot begin|alternate spelling" }
  }
};

template <int N> struct Foo2 {};
template struct Foo2<::B>;  // { dg-error "cannot begin|alternate spelling|type/value mismatch|expected a constant" }

int value = 0;

void func(void)
{
  Foo<::B> f; // { dg-error "cannot begin|alternate spelling" }
  f.Foo<B>::method();
  f.Foo<::B>::method(); // { dg-error "cannot begin|alternate spelling" }

  // Check cases where we the token sequence is the correct one, but there
  //  was no digraph or whitespaces in the middle, so we should not emit
  //  the special error message.
  Foo<: :B> k2;     // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" }
  Foo[:B> k1;       // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" } 
// { dg-error "" "" { target *-*-* } 40 }
// { dg-error "" "" { target *-*-* } 41 }

  int Foo[2];
  Foo[::value] = 0;
}

template struct Foo<::B>; // { dg-error "cannot begin|alternate spelling" }

// On the first error message, an additional note about the use of 
//  -fpermissive should be present
// { dg-error "-fpermissive" "-fpermissive" { target *-*-* } 18 }