summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-02-22 01:22:29 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-02-22 01:22:29 +0000
commit23eb9f707bf66797f9bd435a411a7e2fde3be4a7 (patch)
treec5762119cc3e638f2affae1eda58e3fc784fac42
parentc2fa8fafde2e48812130acc0e15a53d324c59c09 (diff)
downloadbcm5719-llvm-23eb9f707bf66797f9bd435a411a7e2fde3be4a7.tar.gz
bcm5719-llvm-23eb9f707bf66797f9bd435a411a7e2fde3be4a7.zip
In Objective-C, there are no trailing return types, so don't produce diagnostics suggesting they are missing.
llvm-svn: 126174
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaType.cpp13
-rw-r--r--clang/test/SemaObjC/auto-objective-c.m3
3 files changed, 14 insertions, 4 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e29547c6612..2c075cb098b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -905,7 +905,7 @@ def err_auto_not_allowed : Error<
"'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<
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 9468b9c74a3..7c96a3f2de3 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1451,8 +1451,11 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
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 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
break;
case Declarator::TypeNameContext:
if (!AutoAllowedInTypeName)
- Error = 9; // Generic
+ Error = 10; // Generic
break;
case Declarator::FileContext:
case Declarator::BlockContext:
@@ -1496,11 +1499,15 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
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);
diff --git a/clang/test/SemaObjC/auto-objective-c.m b/clang/test/SemaObjC/auto-objective-c.m
index e73f899ac6b..e5d0179aa6c 100644
--- a/clang/test/SemaObjC/auto-objective-c.m
+++ b/clang/test/SemaObjC/auto-objective-c.m
@@ -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);
OpenPOWER on IntegriCloud