aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-02-22 23:17:49 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-02-22 23:17:49 +0000
commit12e3ecec906f65580059a9d8555849a272c2db81 (patch)
tree80ee9cef00c056398294b94fe75fe75bb54d298b
parent8178df3b39ab923ff5d24538812628abee33df79 (diff)
Provide Fixit warning when 'auto' is intended as storage
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
-rw-r--r--include/clang/Basic/DiagnosticParseKinds.td4
-rw-r--r--lib/Parse/ParseDecl.cpp16
-rw-r--r--test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp2
-rw-r--r--test/FixIt/auto-fixit.m11
-rw-r--r--test/SemaCXX/auto-cxx0x.cpp2
-rw-r--r--test/SemaObjC/auto-objective-c.m6
6 files changed, 36 insertions, 5 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td
index 7e20d20cd2..9a68af9c45 100644
--- a/include/clang/Basic/DiagnosticParseKinds.td
+++ b/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/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 2999fdf5d4..5828bfa114 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/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/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp
index 81f1a9f96e..b675fb8013 100644
--- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp
+++ b/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/test/FixIt/auto-fixit.m b/test/FixIt/auto-fixit.m
new file mode 100644
index 0000000000..d09f04c2b7
--- /dev/null
+++ b/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/test/SemaCXX/auto-cxx0x.cpp b/test/SemaCXX/auto-cxx0x.cpp
index 654acb5ad2..f9246beff9 100644
--- a/test/SemaCXX/auto-cxx0x.cpp
+++ b/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/test/SemaObjC/auto-objective-c.m b/test/SemaObjC/auto-objective-c.m
index e5d0179aa6..5467e24a79 100644
--- a/test/SemaObjC/auto-objective-c.m
+++ b/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}}
+}