| 1 |
// PR c++/25814 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-additional-options "-fdiagnostics-show-caret" } |
| 4 |
// Test -Wvexing-parse's fix-it hints in C++11. |
| 5 |
|
| 6 |
#include <initializer_list> |
| 7 |
|
| 8 |
struct X { }; |
| 9 |
|
| 10 |
struct S { |
| 11 |
S(X); |
| 12 |
S(std::initializer_list<X>); |
| 13 |
int m; |
| 14 |
}; |
| 15 |
|
| 16 |
struct T { |
| 17 |
T(X); |
| 18 |
int m; |
| 19 |
}; |
| 20 |
|
| 21 |
struct W { |
| 22 |
W(); |
| 23 |
W(std::initializer_list<X>); |
| 24 |
int m; |
| 25 |
}; |
| 26 |
|
| 27 |
struct U { |
| 28 |
U(); |
| 29 |
int m; |
| 30 |
}; |
| 31 |
|
| 32 |
int |
| 33 |
main () |
| 34 |
{ |
| 35 |
/* |
| 36 |
Careful what we're suggesting: |
| 37 |
S a((X())) -> S(X) |
| 38 |
S a({X()}) -> (std::initializer_list<X>) |
| 39 |
S a{X()} -> (std::initializer_list<X>) |
| 40 |
*/ |
| 41 |
S a(X()); // { dg-warning "6:parentheses were disambiguated as a function declaration" } |
| 42 |
/* { dg-begin-multiline-output "" } |
| 43 |
S a(X()); |
| 44 |
^~~~~ |
| 45 |
{ dg-end-multiline-output "" } */ |
| 46 |
// { dg-message "6:add parentheses to declare a variable" "" { target *-*-* } 41 } |
| 47 |
/* { dg-begin-multiline-output "" } |
| 48 |
S a(X()); |
| 49 |
^~~~~ |
| 50 |
( ) |
| 51 |
{ dg-end-multiline-output "" } */ |
| 52 |
|
| 53 |
T t(X()); // { dg-warning "6:parentheses were disambiguated as a function declaration" } |
| 54 |
/* { dg-begin-multiline-output "" } |
| 55 |
T t(X()); |
| 56 |
^~~~~ |
| 57 |
{ dg-end-multiline-output "" } */ |
| 58 |
// { dg-message "6:replace parentheses with braces to declare a variable" "" { target *-*-* } 53 } |
| 59 |
/* { dg-begin-multiline-output "" } |
| 60 |
T t(X()); |
| 61 |
^~~~~ |
| 62 |
- |
| 63 |
{ - |
| 64 |
} |
| 65 |
{ dg-end-multiline-output "" } */ |
| 66 |
|
| 67 |
int n( ); // { dg-warning "8:empty parentheses were disambiguated as a function declaration" } |
| 68 |
/* { dg-begin-multiline-output "" } |
| 69 |
int n( ); |
| 70 |
^~~~~ |
| 71 |
{ dg-end-multiline-output "" } */ |
| 72 |
// { dg-message "8:remove parentheses to default-initialize a variable" "" { target *-*-* } 67 } |
| 73 |
/* { dg-begin-multiline-output "" } |
| 74 |
int n( ); |
| 75 |
^~~~~ |
| 76 |
----- |
| 77 |
{ dg-end-multiline-output "" } */ |
| 78 |
// { dg-message "8:or replace parentheses with braces to value-initialize a variable" "" { target *-*-* } 67 } |
| 79 |
|
| 80 |
S s(); // { dg-warning "6:empty parentheses were disambiguated as a function declaration" } |
| 81 |
/* { dg-begin-multiline-output "" } |
| 82 |
S s(); |
| 83 |
^~ |
| 84 |
{ dg-end-multiline-output "" } */ |
| 85 |
|
| 86 |
X x(); // { dg-warning "6:empty parentheses were disambiguated as a function declaration" } |
| 87 |
/* { dg-begin-multiline-output "" } |
| 88 |
X x(); |
| 89 |
^~ |
| 90 |
{ dg-end-multiline-output "" } */ |
| 91 |
// { dg-message "6:remove parentheses to default-initialize a variable" "" { target *-*-* } 86 } |
| 92 |
/* { dg-begin-multiline-output "" } |
| 93 |
X x(); |
| 94 |
^~ |
| 95 |
-- |
| 96 |
{ dg-end-multiline-output "" } */ |
| 97 |
// { dg-message "6:or replace parentheses with braces to aggregate-initialize a variable" "" { target *-*-* } 86 } |
| 98 |
|
| 99 |
W w(); // { dg-warning "6:empty parentheses were disambiguated as a function declaration" } |
| 100 |
/* { dg-begin-multiline-output "" } |
| 101 |
W w(); |
| 102 |
^~ |
| 103 |
{ dg-end-multiline-output "" } */ |
| 104 |
// { dg-message "6:remove parentheses to default-initialize a variable" "" { target *-*-* } 99 } |
| 105 |
/* { dg-begin-multiline-output "" } |
| 106 |
W w(); |
| 107 |
^~ |
| 108 |
-- |
| 109 |
{ dg-end-multiline-output "" } */ |
| 110 |
|
| 111 |
T t2(); // { dg-warning "7:empty parentheses were disambiguated as a function declaration" } |
| 112 |
/* { dg-begin-multiline-output "" } |
| 113 |
T t2(); |
| 114 |
^~ |
| 115 |
{ dg-end-multiline-output "" } */ |
| 116 |
|
| 117 |
U u(); // { dg-warning "6:empty parentheses were disambiguated as a function declaration" } |
| 118 |
/* { dg-begin-multiline-output "" } |
| 119 |
U u(); |
| 120 |
^~ |
| 121 |
{ dg-end-multiline-output "" } */ |
| 122 |
// { dg-message "6:remove parentheses to default-initialize a variable" "" { target *-*-* } 117 } |
| 123 |
/* { dg-begin-multiline-output "" } |
| 124 |
U u(); |
| 125 |
^~ |
| 126 |
-- |
| 127 |
{ dg-end-multiline-output "" } */ |
| 128 |
// { dg-message "6:or replace parentheses with braces to value-initialize a variable" "" { target *-*-* } 117 } |
| 129 |
} |