]> granicus.if.org Git - clang/commitdiff
objective-c nonfragile abi: discourage ivar declarations
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 15 May 2012 16:33:04 +0000 (16:33 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 15 May 2012 16:33:04 +0000 (16:33 +0000)
in @interface by issuing warning (off by default) under
opt'ed in flag -Winterface-block-ivar. // rdar://10763173

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaObjC/no-ivar-in-interface-block.m [new file with mode: 0644]

index 72e9b86260534096fd0e45461526b0bd86b41c52..2a34b53e4d46ccca94c95fbbf76dff418515aba2 100644 (file)
@@ -3024,6 +3024,9 @@ def err_redefinition_of_enumerator : Error<"redefinition of enumerator %0">;
 def err_duplicate_member : Error<"duplicate member %0">;
 def err_misplaced_ivar : Error<
   "ivars may not be placed in %select{categories|class extension}0">;
+def warn_ivar_in_interface_block : Warning<
+  "declaration of ivar in the interface block is deprecated">,
+  InGroup<DiagGroup<"interface-block-ivar">>, DefaultIgnore;
 def ext_enum_value_not_int : Extension<
   "ISO C restricts enumerator values to range of 'int' (%0 is too "
   "%select{small|large}1)">;
index 9e7f28b24d4274f1a2a7df34cf725a2376154cb7..7c87aa1e8175818c51a74a1b2becd8b6c5fb715f 100644 (file)
@@ -9540,7 +9540,11 @@ Decl *Sema::ActOnIvar(Scope *S,
     S->AddDecl(NewID);
     IdResolver.AddDecl(NewID);
   }
-
+  
+  if (LangOpts.ObjCNonFragileABI2 &&
+      !NewID->isInvalidDecl() && isa<ObjCInterfaceDecl>(EnclosingDecl))
+    Diag(Loc, diag::warn_ivar_in_interface_block);
+  
   return NewID;
 }
 
diff --git a/test/SemaObjC/no-ivar-in-interface-block.m b/test/SemaObjC/no-ivar-in-interface-block.m
new file mode 100644 (file)
index 0000000..ce98586
--- /dev/null
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1  -fsyntax-only -verify -Winterface-block-ivar %s
+// rdar://10763173
+
+@interface I
+{
+  @protected  int P_IVAR; // expected-warning {{declaration of ivar in the interface block is deprecated}}
+
+  @public     int PU_IVAR; // expected-warning {{declaration of ivar in the interface block is deprecated}}
+
+  @private    int PRV_IVAR; // expected-warning {{declaration of ivar in the interface block is deprecated}}
+}
+@end
+
+@interface I()
+{
+  int I1;
+  int I2;
+}
+@end
+
+@interface I()
+{
+  int I3, I4;
+}
+@end
+
+@implementation I
+{
+  int I5;
+  int I6;
+}
+@end