]> granicus.if.org Git - clang/commitdiff
objc: When issue diagnostic about deprecated method, also
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 2 Mar 2012 21:50:02 +0000 (21:50 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 2 Mar 2012 21:50:02 +0000 (21:50 +0000)
issue the note if it is because message is sent to a forward class
declaration in delayed diagnostic. // rdar://10290322

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

include/clang/Sema/DelayedDiagnostic.h
lib/Sema/DelayedDiagnostic.cpp
lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/warn-forward-class-attr-deprecated.m [new file with mode: 0644]

index dd2603dbc362092b20c08fcd6049be33abcc35ec..3320cd815a6b6af75c5f6f93f90b333c89fa5522 100644 (file)
@@ -122,8 +122,9 @@ public:
   void Destroy();
 
   static DelayedDiagnostic makeDeprecation(SourceLocation Loc,
-                                           const NamedDecl *D,
-                                           StringRef Msg);
+           const NamedDecl *D,
+           const ObjCInterfaceDecl *UnknownObjCClass,
+           StringRef Msg);
 
   static DelayedDiagnostic makeAccess(SourceLocation Loc,
                                       const AccessedEntity &Entity) {
@@ -187,12 +188,17 @@ public:
     assert(Kind == ForbiddenType && "not a forbidden-type diagnostic");
     return QualType::getFromOpaquePtr(ForbiddenTypeData.OperandType);
   }
+  
+  const ObjCInterfaceDecl *getUnknownObjCClass() const {
+    return DeprecationData.UnknownObjCClass;
+  }
 
 private:
   union {
     /// Deprecation.
     struct {
       const NamedDecl *Decl;
+      const ObjCInterfaceDecl *UnknownObjCClass;
       const char *Message;
       size_t MessageLen;
     } DeprecationData;
index d6c1ad13a854a78064d96b07293db4edc9a12450..876f9d7a95458efa299ec947e1cefe7126385a74 100644 (file)
@@ -20,13 +20,15 @@ using namespace clang;
 using namespace sema;
 
 DelayedDiagnostic DelayedDiagnostic::makeDeprecation(SourceLocation Loc,
-                                                     const NamedDecl *D,
-                                                     StringRef Msg) {
+                                    const NamedDecl *D,
+                                    const ObjCInterfaceDecl *UnknownObjCClass,
+                                    StringRef Msg) {
   DelayedDiagnostic DD;
   DD.Kind = Deprecation;
   DD.Triggered = false;
   DD.Loc = Loc;
   DD.DeprecationData.Decl = D;
+  DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
   char *MessageData = 0;
   if (Msg.size()) {
     MessageData = new char [Msg.size()];
index 4f3b03f6e511d1d97eee06b6cdc9ce772e0c527d..37edeff0ecd0ad28e12d3b5775350899b386aa5c 100644 (file)
@@ -4121,6 +4121,11 @@ void Sema::HandleDelayedDeprecationCheck(DelayedDiagnostic &DD,
     Diag(DD.Loc, diag::warn_deprecated_message)
       << DD.getDeprecationDecl()->getDeclName()
       << DD.getDeprecationMessage();
+  else if (DD.getUnknownObjCClass()) {
+    Diag(DD.Loc, diag::warn_deprecated_fwdclass_message) 
+      << DD.getDeprecationDecl()->getDeclName();
+    Diag(DD.getUnknownObjCClass()->getLocation(), diag::note_forward_class);
+  }
   else
     Diag(DD.Loc, diag::warn_deprecated)
       << DD.getDeprecationDecl()->getDeclName();
@@ -4131,7 +4136,9 @@ void Sema::EmitDeprecationWarning(NamedDecl *D, StringRef Message,
                                   const ObjCInterfaceDecl *UnknownObjCClass) {
   // Delay if we're currently parsing a declaration.
   if (DelayedDiagnostics.shouldDelayDiagnostics()) {
-    DelayedDiagnostics.add(DelayedDiagnostic::makeDeprecation(Loc, D, Message));
+    DelayedDiagnostics.add(DelayedDiagnostic::makeDeprecation(Loc, D, 
+                                                              UnknownObjCClass,
+                                                              Message));
     return;
   }
 
diff --git a/test/SemaObjC/warn-forward-class-attr-deprecated.m b/test/SemaObjC/warn-forward-class-attr-deprecated.m
new file mode 100644 (file)
index 0000000..26e0196
--- /dev/null
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// rdar://10290322
+
+@class ABGroupImportFilesScope; // expected-note {{forward declaration of class here}}
+
+@interface I1
+- (id) filenames __attribute__((deprecated));
+@end
+
+@interface I2
+- (id) Meth : (ABGroupImportFilesScope*) scope;
+- (id) filenames __attribute__((deprecated));
+- (id)initWithAccount: (id)account filenames:(id)filenames;
+@end
+
+@implementation I2
+- (id) Meth : (ABGroupImportFilesScope*) scope
+{
+  id p =  [self initWithAccount : 0 filenames :[scope filenames]]; // expected-warning {{'filenames' maybe deprecated because receiver type is unknown}}
+  return 0;
+}
+- (id) filenames { return 0; }
+- (id)initWithAccount: (id)account filenames:(id)filenames { return 0; }
+@end