| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-fshow-column" } |
| 3 |
// Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org> |
| 4 |
// Try to find out when the digraph '<:' is used as a mistake, and parse it |
| 5 |
// correctly to avoid cascaded errors. |
| 6 |
|
| 7 |
struct B; |
| 8 |
|
| 9 |
template <class A> |
| 10 |
struct Foo |
| 11 |
{ |
| 12 |
template <class T> |
| 13 |
struct Nested |
| 14 |
{ |
| 15 |
static void method(void) {} |
| 16 |
}; |
| 17 |
|
| 18 |
void method(void) { |
| 19 |
typename Foo<::B>::template Nested<::B> n; // { dg-error "17:'<::' cannot begin" "17-begin" { target { ! c++11 } } } |
| 20 |
// { dg-message "17:'<:' is an alternate spelling" "17-alt" { target { ! c++11 } } .-1 } |
| 21 |
// { dg-error "39:'<::' cannot begin" "39-begin" { target { ! c++11 } } .-2 } |
| 22 |
// { dg-message "39:'<:' is an alternate spelling" "39-alt" { target { ! c++11 } } .-3 } |
| 23 |
n.template Nested<B>::method(); |
| 24 |
n.template Nested<::B>::method(); // { dg-error "22:'<::' cannot begin" "error" { target { ! c++11 } } } |
| 25 |
// { dg-message "22:'<:' is an alternate" "note" { target { ! c++11 } } .-1 } |
| 26 |
Nested<B>::method(); |
| 27 |
Nested<::B>::method(); // { dg-error "11:'<::' cannot begin" "error" { target { ! c++11 } } } |
| 28 |
// { dg-message "11:'<:' is an alternate" "note" { target { ! c++11 } } .-1 } |
| 29 |
} |
| 30 |
}; |
| 31 |
|
| 32 |
template <int N> struct Foo2 {}; |
| 33 |
template struct Foo2<::B>; // { dg-error "21:'<::' cannot begin" "begin" { target { ! c++11 } } } |
| 34 |
// { dg-message "21:'<:' is an alternate" "alt" { target { ! c++11 } } .-1 } |
| 35 |
// { dg-message "25:type/value mismatch" "mismatch" { target *-*-* } .-2 } |
| 36 |
// { dg-message "25:expected a constant" "const" { target *-*-* } .-3 } |
| 37 |
|
| 38 |
int value = 0; |
| 39 |
|
| 40 |
void func(void) |
| 41 |
{ |
| 42 |
Foo<::B> f; // { dg-error "cannot begin" "begin" { target { ! c++11 } } } |
| 43 |
// { dg-message "alternate spelling" "alt" { target { ! c++11 } } .-1 } |
| 44 |
f.Foo<B>::method(); |
| 45 |
f.Foo<::B>::method(); // { dg-error "8:cannot begin" "begin" { target { ! c++11 } } } |
| 46 |
// { dg-message "8:alternate spelling" "alt" { target { ! c++11 } } .-1 } |
| 47 |
|
| 48 |
// Check cases where we the token sequence is the correct one, but there |
| 49 |
// was no digraph or whitespaces in the middle, so we should not emit |
| 50 |
// the special error message. |
| 51 |
Foo<: :B> k2; // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" } |
| 52 |
Foo[:B> k1; // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" } |
| 53 |
// { dg-error "6:missing template arguments before" "template" { target c++14_down } .-2 } |
| 54 |
// { dg-error "9:expected primary-expression before ':' token" "primary" { target c++14_down } .-3 } |
| 55 |
// { dg-error "8:expected '\]' before ':' token" "backslash" { target c++14_down } .-4 } |
| 56 |
// { dg-error "6:missing template arguments before" "template" { target c++14_down } .-4 } |
| 57 |
// { dg-error "7:expected primary-expression before ':' token" "primary" { target c++14_down } .-5 } |
| 58 |
// { dg-error "7:expected '\]' before ':' token" "backslash" { target c++14_down } .-6 } |
| 59 |
// { dg-error "9:expected identifier" "" { target c++17 } .-8 } |
| 60 |
// { dg-error "8:expected" "" { target c++17 } .-9 } |
| 61 |
// { dg-error "7:expected identifier" "" { target c++17 } .-9 } |
| 62 |
// { dg-error "7:expected" "" { target c++17 } .-10 } |
| 63 |
// |
| 64 |
int Foo[2]; |
| 65 |
Foo[::value] = 0; |
| 66 |
} |
| 67 |
|
| 68 |
template struct Foo<::B>; // { dg-error "20:'<::' cannot begin" "begin" { target { ! c++11 } } } |
| 69 |
// { dg-message "20:is an alternate" "alt" { target { ! c++11 } } .-1 } |
| 70 |
|
| 71 |
// On the first error message, an additional note about the use of |
| 72 |
// -fpermissive should be present |
| 73 |
// { 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 } |