diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.def | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | test/SemaObjC/objc2-warn-weak-decl.m | 10 |
3 files changed, 17 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index 05c46563bb..cce97aa48f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -361,6 +361,8 @@ DIAG(warn_attribute_ignored, WARNING, "%0 attribute ignored") DIAG(warn_attribute_weak_on_field, WARNING, "__weak attribute cannot be specified on a field declaration") +DIAG(warn_attribute_weak_on_local, WARNING, + "__weak attribute cannot be specified on an automatic variable") DIAG(warn_attribute_wrong_decl_type, WARNING, "'%0' attribute only applies to %select{function|union|" "variable and function|function or method}1 types") diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 51c479040b..3130f02bef 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1592,6 +1592,11 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, Diag(D.getIdentifierLoc(), diag::err_as_qualified_auto_decl); InvalidDecl = true; } + + if (NewVD->hasLocalStorage() && NewVD->getType().isObjCGCWeak()) { + Diag(D.getIdentifierLoc(), diag::warn_attribute_weak_on_local); + } + // Merge the decl with the existing one if appropriate. If the decl is // in an outer scope, it isn't the same thing. if (PrevDecl && isDeclInScope(PrevDecl, DC, S)) { diff --git a/test/SemaObjC/objc2-warn-weak-decl.m b/test/SemaObjC/objc2-warn-weak-decl.m new file mode 100644 index 0000000000..8fde620e71 --- /dev/null +++ b/test/SemaObjC/objc2-warn-weak-decl.m @@ -0,0 +1,10 @@ +// RUN: clang -fsyntax-only -fobjc-gc -verify %s +struct S { + __weak id p; // expected-warning {{__weak attribute cannot be specified on a field declaration}} +}; + +int main () +{ + __weak id local; // expected-warning {{__weak attribute cannot be specified on an automatic variable}} +} + |