diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-29 23:57:25 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-29 23:57:25 +0000 |
| commit | ac63d63543ca824434236ffd788c46eec9339657 (patch) | |
| tree | b55ea78a09084f92211b3b4bbd8d7e69bf18260c /clang/test/SemaCXX/decl-expr-ambiguity.cpp | |
| parent | 1d8cf2be89087a2babc1dc38b16040fad0a555e2 (diff) | |
| download | bcm5719-llvm-ac63d63543ca824434236ffd788c46eec9339657.tar.gz bcm5719-llvm-ac63d63543ca824434236ffd788c46eec9339657.zip | |
Add a "vexing parse" warning for ambiguity between a variable declaration and a
function-style cast.
This fires for cases such as
T(x);
... where 'x' was previously declared and T is a type. This construct declares
a variable named 'x' rather than the (probably expected) interpretation of a
function-style cast of 'x' to T.
llvm-svn: 314570
Diffstat (limited to 'clang/test/SemaCXX/decl-expr-ambiguity.cpp')
| -rw-r--r-- | clang/test/SemaCXX/decl-expr-ambiguity.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/decl-expr-ambiguity.cpp b/clang/test/SemaCXX/decl-expr-ambiguity.cpp index 1b1f7dc8a70..1e31d701d0c 100644 --- a/clang/test/SemaCXX/decl-expr-ambiguity.cpp +++ b/clang/test/SemaCXX/decl-expr-ambiguity.cpp @@ -48,13 +48,20 @@ void f() { struct RAII { RAII(); + RAII(int); ~RAII(); }; +struct NotRAII { + NotRAII(); + NotRAII(int); +}; + void func(); void func2(short); namespace N { struct S; + int n; void emptyParens() { RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}} @@ -69,6 +76,23 @@ namespace N { void nonEmptyParens() { int f = 0, // g = 0; expected-note {{change this ',' to a ';' to call 'func2'}} func2(short(f)); // expected-warning {{function declaration}} expected-note {{add a pair of parentheses}} + + RAII(n); // expected-warning {{parentheses were disambiguated as redundant parentheses around declaration of variable named 'n'}} + // expected-note@-1 {{add a variable name to declare a 'RAII' initialized with 'n'}} + // expected-note@-2 {{add enclosing parentheses to perform a function-style cast}} + // expected-note@-3 {{remove parentheses to silence this warning}} + + RAII(undeclared1); +#pragma clang diagnostic push +#pragma clang diagnostic warning "-Wredundant-parens" + RAII(undeclared2); // expected-warning {{redundant parentheses surrounding declarator}} +#pragma clang diagnostic pop + + { + NotRAII(n); // expected-warning {{parentheses were disambiguated as redundant parentheses around declaration of variable named 'n'}} + // expected-note@-1 {{add enclosing parentheses to perform a function-style cast}} + // expected-note@-2 {{remove parentheses to silence this warning}} + } } } |

