[cfe-commits] r126261 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDecl.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp test/FixIt/auto-fixit.m test/SemaCXX/auto-cxx0x.cpp test/SemaObjC/auto-objective-c.m

Fariborz Jahanian fjahanian at apple.com
Tue Feb 22 15:17:49 PST 2011


Author: fjahanian
Date: Tue Feb 22 17:17:49 2011
New Revision: 126261

URL: http://llvm.org/viewvc/llvm-project?rev=126261&view=rev
Log:
Provide Fixit warning when 'auto' is intended as storage
specifier in legacy code. Patch is reviewed offline by Doug.
// rdar://9036633.

Added:
    cfe/trunk/test/FixIt/auto-fixit.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp
    cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
    cfe/trunk/test/SemaObjC/auto-objective-c.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=126261&r1=126260&r2=126261&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Feb 22 17:17:49 2011
@@ -28,6 +28,10 @@
 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'">;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=126261&r1=126260&r2=126261&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Feb 22 17:17:49 2011
@@ -1246,9 +1246,18 @@
                                          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 @@
       else
         Diag(Tok, DiagID) << PrevSpec;
     }
+
     DS.SetRangeEnd(Tok.getLocation());
     ConsumeToken();
   }

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp?rev=126261&r1=126260&r2=126261&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp Tue Feb 22 17:17:49 2011
@@ -39,7 +39,7 @@
   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;

Added: cfe/trunk/test/FixIt/auto-fixit.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/auto-fixit.m?rev=126261&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/auto-fixit.m (added)
+++ cfe/trunk/test/FixIt/auto-fixit.m Tue Feb 22 17:17:49 2011
@@ -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;
+}

Modified: cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/auto-cxx0x.cpp?rev=126261&r1=126260&r2=126261&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/auto-cxx0x.cpp (original)
+++ cfe/trunk/test/SemaCXX/auto-cxx0x.cpp Tue Feb 22 17:17:49 2011
@@ -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}}
 }

Modified: cfe/trunk/test/SemaObjC/auto-objective-c.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/auto-objective-c.m?rev=126261&r1=126260&r2=126261&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/auto-objective-c.m (original)
+++ cfe/trunk/test/SemaObjC/auto-objective-c.m Tue Feb 22 17:17:49 2011
@@ -25,3 +25,9 @@
   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}}
+}





More information about the cfe-commits mailing list