diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2011-02-22 23:17:49 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-02-22 23:17:49 +0000 |
| commit | bb6db5602855643d2af38be21e1972b3f4081cd9 (patch) | |
| tree | 12d6562a30cb89b238c540ea42f154038c28923d | |
| parent | 1971900fdc56df4aa8c220bea43f78c87bb048c7 (diff) | |
| download | bcm5719-llvm-bb6db5602855643d2af38be21e1972b3f4081cd9.tar.gz bcm5719-llvm-bb6db5602855643d2af38be21e1972b3f4081cd9.zip | |
Provide Fixit warning when 'auto' is intended as storage
specifier in legacy code. Patch is reviewed offline by Doug.
// rdar://9036633.
llvm-svn: 126261
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticParseKinds.td | 4 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 16 | ||||
| -rw-r--r-- | clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp | 2 | ||||
| -rw-r--r-- | clang/test/FixIt/auto-fixit.m | 11 | ||||
| -rw-r--r-- | clang/test/SemaCXX/auto-cxx0x.cpp | 2 | ||||
| -rw-r--r-- | clang/test/SemaObjC/auto-objective-c.m | 6 |
6 files changed, 36 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 7e20d20cd23..9a68af9c45c 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -28,6 +28,10 @@ def ext_extra_struct_semi : Extension< def ext_extra_ivar_semi : Extension< "extra ';' inside instance variable list">; +def auto_storage_class : ExtWarn< + "'auto' storage class specifier is redundant and will be " + "removed in future releases">; + def ext_duplicate_declspec : Extension<"duplicate '%0' declaration specifier">; def ext_plain_complex : ExtWarn< "plain '_Complex' requires a type specifier; assuming '_Complex double'">; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 2999fdf5d4b..5828bfa114c 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1246,9 +1246,18 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, DiagID, getLang()); break; case tok::kw_auto: - if (getLang().CPlusPlus0x || getLang().ObjC1) - isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, - DiagID); + if (getLang().CPlusPlus0x || getLang().ObjC2) { + if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { + isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec, + DiagID, getLang()); + if (!isInvalid) + Diag(Tok, diag::auto_storage_class) + << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc()); + } + else + isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, + DiagID); + } else isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec, DiagID, getLang()); @@ -1461,6 +1470,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, else Diag(Tok, DiagID) << PrevSpec; } + DS.SetRangeEnd(Tok.getLocation()); ConsumeToken(); } diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp index 81f1a9f96e2..b675fb8013e 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp @@ -39,7 +39,7 @@ void p3example() { auto x = 5; const auto *v = &x, u = 6; static auto y = 0.0; - auto int r; // expected-error{{cannot combine with previous}} expected-error{{requires an initializer}} + auto int r; // expected-warning {{'auto' storage class specifier is redundant and will be removed in future releases}} same<decltype(x), int> xHasTypeInt; same<decltype(v), const int*> vHasTypeConstIntPtr; diff --git a/clang/test/FixIt/auto-fixit.m b/clang/test/FixIt/auto-fixit.m new file mode 100644 index 00000000000..d09f04c2b79 --- /dev/null +++ b/clang/test/FixIt/auto-fixit.m @@ -0,0 +1,11 @@ +/* RUN: cp %s %t + RUN: %clang_cc1 -x objective-c -fixit %t + RUN: %clang_cc1 -x objective-c -Werror %t + */ + +// rdar://9036633 + +int main() { + auto int i = 0; + return i; +} diff --git a/clang/test/SemaCXX/auto-cxx0x.cpp b/clang/test/SemaCXX/auto-cxx0x.cpp index 654acb5ad20..f9246beff92 100644 --- a/clang/test/SemaCXX/auto-cxx0x.cpp +++ b/clang/test/SemaCXX/auto-cxx0x.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x void f() { - auto int a; // expected-error{{cannot combine with previous 'auto' declaration specifier}} // expected-error{{declaration of variable 'a' with type 'auto' requires an initializer}} + auto int a; // expected-warning {{'auto' storage class specifier is redundant and will be removed in future releases}} int auto b; // expected-error{{cannot combine with previous 'int' declaration specifier}} } diff --git a/clang/test/SemaObjC/auto-objective-c.m b/clang/test/SemaObjC/auto-objective-c.m index e5d0179aa6c..5467e24a795 100644 --- a/clang/test/SemaObjC/auto-objective-c.m +++ b/clang/test/SemaObjC/auto-objective-c.m @@ -25,3 +25,9 @@ typedef int (^P) (int x); return my_block; } @end + + +// rdar://9036633 +int main() { + auto int auto_i = 7; // expected-warning {{'auto' storage class specifier is redundant and will be removed in future releases}} +} |

