aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaDecl.cpp6
-rw-r--r--test/SemaObjC/no-ivar-in-interface-block.m32
3 files changed, 40 insertions, 1 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 72e9b86260..2a34b53e4d 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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)">;
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 9e7f28b24d..7c87aa1e81 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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
index 0000000000..ce98586306
--- /dev/null
+++ b/test/SemaObjC/no-ivar-in-interface-block.m
@@ -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