File: error11.C

package info (click to toggle)
gcc-arm-none-eabi 15%3A8-2019-q3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 571,828 kB
  • sloc: ansic: 2,937,651; cpp: 881,644; ada: 597,189; makefile: 65,528; asm: 56,499; xml: 46,621; exp: 24,747; sh: 19,684; python: 7,256; pascal: 4,370; awk: 3,497; perl: 2,695; yacc: 316; ml: 285; f90: 234; lex: 198; objc: 194; haskell: 119
file content (69 lines) | stat: -rw-r--r-- 3,331 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// { dg-do compile }
// { dg-options "-fshow-column" }"
// 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 "17:'<::' cannot begin" "17-begin" { target { ! c++11 } } }
// { dg-message "17:'<:' is an alternate spelling" "17-alt" { target { ! c++11 } } .-1 }
// { dg-error "39:'<::' cannot begin" "39-begin" { target { ! c++11 } } .-2 }
// { dg-message "39:'<:' is an alternate spelling" "39-alt" { target { ! c++11 } } .-3 }
    n.template Nested<B>::method();
    n.template Nested<::B>::method();  // { dg-error "22:'<::' cannot begin" "error" { target { ! c++11 } } }
// { dg-message "22:'<:' is an alternate" "note" { target { ! c++11 } } .-1 }
    Nested<B>::method();
    Nested<::B>::method(); // { dg-error "11:'<::' cannot begin" "error" { target { ! c++11 } } }
// { dg-message "11:'<:' is an alternate" "note" { target { ! c++11 } } .-1 }
  }
};

template <int N> struct Foo2 {};
template struct Foo2<::B>;  // { dg-error "21:'<::' cannot begin" "begin" { target { ! c++11 } } }
// { dg-message "21:'<:' is an alternate" "alt" { target { ! c++11 } } .-1 }
// { dg-message "25:type/value mismatch" "mismatch" { target *-*-* } .-2 }
// { dg-message "25:expected a constant" "const" { target *-*-* } .-3 }

int value = 0;

void func(void)
{
  Foo<::B> f; // { dg-error "cannot begin" "begin" { target { ! c++11 } } }
// { dg-message "alternate spelling" "alt" { target { ! c++11 } } .-1 }
  f.Foo<B>::method();
  f.Foo<::B>::method(); // { dg-error "8:cannot begin" "begin" { target { ! c++11 } } }
// { dg-message "8:alternate spelling" "alt" { target { ! c++11 } } .-1 }

  // 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 "6:missing template arguments before" "template" { target *-*-* } 51 }
// { dg-error "9:expected primary-expression before ':' token" "primary" { target *-*-* } 51 }
// { dg-error "8:expected '\]' before ':' token" "backslash" { target *-*-* } 51 }
// { dg-error "6:missing template arguments before" "template" { target *-*-* } 52 }
// { dg-error "7:expected primary-expression before ':' token" "primary" { target *-*-* } 52 }
// { dg-error "7:expected '\]' before ':' token" "backslash" { target *-*-* } 52 }
//
  int Foo[2];
  Foo[::value] = 0;
}

template struct Foo<::B>; // { dg-error "20:'<::' cannot begin" "begin" { target { ! c++11 } } }
// { dg-message "20:is an alternate" "alt" { target { ! c++11 } } .-1 }

// On the first error message, an additional note about the use of 
//  -fpermissive should be present
// { dg-message "17:\\(if you use '-fpermissive' or '-std=c\\+\\+11', or '-std=gnu\\+\\+11' G\\+\\+ will accept your code\\)" "-fpermissive" { target { ! c++11 } } 19 }