]> granicus.if.org Git - clang/commitdiff
Provide Fixit warning when 'auto' is intended as storage
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 22 Feb 2011 23:17:49 +0000 (23:17 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 22 Feb 2011 23:17:49 +0000 (23:17 +0000)
specifier in legacy code. Patch is reviewed offline by Doug.
// rdar://9036633.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126261 91177308-0d34-0410-b5e6-96231b3b80d8

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 [new file with mode: 0644]
test/SemaCXX/auto-cxx0x.cpp
test/SemaObjC/auto-objective-c.m

index 7e20d20cd2338b442ee8aba44ea006efc275df98..9a68af9c45caff1e9da6a64724167228b19e2e44 100644 (file)
@@ -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'">;
index 2999fdf5d4b3f212e982c6d6ba423b20e6ec6b35..5828bfa114cbc1ac788874b0c1ebbb0468653c99 100644 (file)
@@ -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();
   }
index 81f1a9f96e277943ab60948ba875adcf2dbfa15a..b675fb8013e3758e7f97f17ffa4e4681dcd0abfe 100644 (file)
@@ -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/test/FixIt/auto-fixit.m b/test/FixIt/auto-fixit.m
new file mode 100644 (file)
index 0000000..d09f04c
--- /dev/null
@@ -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;
+}
index 654acb5ad20c39049d7a838488bbb38770751fa5..f9246beff92a8df8257b3c96e66134c29affd116 100644 (file)
@@ -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}}
 }
index e5d0179aa6c5ef2dc4cf95fc68ba96fa2efe0999..5467e24a795145582283e8ad611d74c99e532cec 100644 (file)
@@ -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}}
+}