diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-10-02 05:36:02 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-10-02 05:36:02 +0000 |
commit | 3ba17ee280d58bf702eb3836c119bab42dcbb9c8 (patch) | |
tree | c6f32d211ed67995dd115804a344c9a8a0eba0b2 | |
parent | be9af1288881110e406b87914162eaa59f1e5918 (diff) |
Tweak diagnostic text to indicate that __weak on a local variable is only allowed
for ARC. Fixes <rdar://problem/12407705>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164990 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 4 | ||||
-rw-r--r-- | test/SemaObjC/nonarc-weak.m | 16 |
3 files changed, 21 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a527c84b43..648fe0b94a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1744,7 +1744,8 @@ def warn_nsobject_attribute : Warning< "__attribute ((NSObject)) may be put on a typedef only, " "attribute is ignored">, InGroup<NSobjectAttribute>; def warn_attribute_weak_on_local : Warning< - "__weak attribute cannot be specified on an automatic variable">, + "__weak attribute cannot be specified on an automatic variable when ARC " + "is not enabled">, InGroup<IgnoredAttributes>; def warn_weak_identifier_undeclared : Warning< "weak identifier %0 never declared">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4382432a6f..ddb41edc64 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4578,8 +4578,10 @@ bool Sema::CheckVariableDeclaration(VarDecl *NewVD, && !NewVD->hasAttr<BlocksAttr>()) { if (getLangOpts().getGC() != LangOptions::NonGC) Diag(NewVD->getLocation(), diag::warn_gc_attribute_weak_on_local); - else + else { + assert(!getLangOpts().ObjCAutoRefCount); Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local); + } } bool isVM = T->isVariablyModifiedType(); diff --git a/test/SemaObjC/nonarc-weak.m b/test/SemaObjC/nonarc-weak.m new file mode 100644 index 0000000000..912a0b160b --- /dev/null +++ b/test/SemaObjC/nonarc-weak.m @@ -0,0 +1,16 @@ +// RUN: %clang -fsyntax-only -Wunused-function %s > %t.nonarc 2>&1 +// RUN: %clang -fsyntax-only -Wunused-function -fobjc-arc %s > %t.arc 2>&1 +// RUN: FileCheck -input-file=%t.nonarc %s +// RUN: FileCheck -input-file=%t.arc -check-prefix=ARC %s + +static void bar() {} // Intentionally unused. + +void foo(id self) { + __weak id weakSelf = self; +} + +// CHECK: 9:13: warning: __weak attribute cannot be specified on an automatic variable when ARC is not enabled +// CHECK: 6:13: warning: unused function 'bar' +// CHECK: 2 warnings generated +// ARC: 6:13: warning: unused function 'bar' +// ARC: 1 warning generated |