]> granicus.if.org Git - clang/commitdiff
Warn on use of __weak attribute on local
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 21 Feb 2009 19:44:02 +0000 (19:44 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 21 Feb 2009 19:44:02 +0000 (19:44 +0000)
variable (objc2 gc specific).

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

include/clang/Basic/DiagnosticSemaKinds.def
lib/Sema/SemaDecl.cpp
test/SemaObjC/objc2-warn-weak-decl.m [new file with mode: 0644]

index 05c46563bbae4790881846bf3097fa25d61e0887..cce97aa48f9dd21a09d260e207fdd0512d1b8b49 100644 (file)
@@ -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")
index 51c479040b6088ced62e941b2cf8482a32c8c197..3130f02bef3b910dc0e114d8942edee5f51b1a08 100644 (file)
@@ -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 (file)
index 0000000..8fde620
--- /dev/null
@@ -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}}
+}
+