[cfe-commits] r126174 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaType.cpp test/SemaObjC/auto-objective-c.m
Richard Smith
richard-llvm at metafoo.co.uk
Mon Feb 21 17:22:30 PST 2011
Author: rsmith
Date: Mon Feb 21 19:22:29 2011
New Revision: 126174
URL: http://llvm.org/viewvc/llvm-project?rev=126174&view=rev
Log:
In Objective-C, there are no trailing return types, so don't produce diagnostics suggesting they are missing.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaObjC/auto-objective-c.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=126174&r1=126173&r2=126174&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Feb 21 19:22:29 2011
@@ -905,7 +905,7 @@
"'auto' not allowed %select{in function prototype|in struct member"
"|in union member|in class member|in exception declaration"
"|in template parameter|in block literal|in template argument"
- "|in typedef|here}0">;
+ "|in typedef|in function return type|here}0">;
def err_auto_var_requires_init : Error<
"declaration of variable %0 with type %1 requires an initializer">;
def err_auto_new_requires_ctor_arg : Error<
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=126174&r1=126173&r2=126174&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Feb 21 19:22:29 2011
@@ -1451,8 +1451,11 @@
distributeTypeAttrsFromDeclarator(state, T);
// C++0x [dcl.spec.auto]p5: reject 'auto' if it is not in an allowed context.
+ // In C++0x, a function declarator using 'auto' must have a trailing return
+ // type (this is checked later) and we can skip this. In other languages
+ // using auto, we need to check regardless.
if (D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto &&
- !D.isFunctionDeclarator()) {
+ (!getLangOptions().CPlusPlus0x || !D.isFunctionDeclarator())) {
int Error = -1;
switch (D.getContext()) {
@@ -1484,7 +1487,7 @@
break;
case Declarator::TypeNameContext:
if (!AutoAllowedInTypeName)
- Error = 9; // Generic
+ Error = 10; // Generic
break;
case Declarator::FileContext:
case Declarator::BlockContext:
@@ -1496,11 +1499,15 @@
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
Error = 8;
+ // In Objective-C it is an error to use 'auto' on a function declarator.
+ if (D.isFunctionDeclarator())
+ Error = 9;
+
// C++0x [dcl.spec.auto]p2: 'auto' is always fine if the declarator
// contains a trailing return type. That is only legal at the outermost
// level. Check all declarator chunks (outermost first) anyway, to give
// better diagnostics.
- if (Error != -1) {
+ if (getLangOptions().CPlusPlus0x && Error != -1) {
for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
unsigned chunkIndex = e - i - 1;
state.setCurrentChunkIndex(chunkIndex);
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=126174&r1=126173&r2=126174&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/auto-objective-c.m (original)
+++ cfe/trunk/test/SemaObjC/auto-objective-c.m Mon Feb 21 19:22:29 2011
@@ -7,6 +7,9 @@
- (id) Meth;
@end
+// Objective-C does not support trailing return types, so check we don't get
+// the C++ diagnostic suggesting we forgot one.
+auto noTrailingReturnType(); // expected-error {{'auto' not allowed in function return type}}
typedef int (^P) (int x);
More information about the cfe-commits
mailing list