]> granicus.if.org Git - clang/commitdiff
Diagnose declaration of reference typed ivars.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Apr 2010 22:07:03 +0000 (22:07 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Apr 2010 22:07:03 +0000 (22:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102390 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaObjCXX/ivar-reference-type.mm [new file with mode: 0644]

index ea31164dd53ce06b301a799e1adcc2fcaa537840..029b5ae99a25f8267bf357fede1120ed021400f9 100644 (file)
@@ -1893,6 +1893,8 @@ def err_out_of_line_declaration : Error<
 def note_member_def_close_match : Note<"member declaration nearly matches">;
 def err_typecheck_ivar_variable_size : Error<
   "instance variables must have a constant size">;
+def err_ivar_reference_type : Error<
+  "instance variables cannot be of reference type">;
 def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_arithmetic_incomplete_type : Error<
index 20e4200fbe124d74881fc28f8c3daa7c7df3f9a3..3f309bb6adaafb2ee62c217dd92315edf008443e 100644 (file)
@@ -5875,10 +5875,13 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S,
     // validate II.
 
   }
-
+  if (T->isReferenceType()) {
+    Diag(Loc, diag::err_ivar_reference_type);
+    D.setInvalidType();
+  }
   // C99 6.7.2.1p8: A member of a structure or union may have any type other
   // than a variably modified type.
-  if (T->isVariablyModifiedType()) {
+  else if (T->isVariablyModifiedType()) {
     Diag(Loc, diag::err_typecheck_ivar_variable_size);
     D.setInvalidType();
   }
diff --git a/test/SemaObjCXX/ivar-reference-type.mm b/test/SemaObjCXX/ivar-reference-type.mm
new file mode 100644 (file)
index 0000000..2b5df45
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+@interface A {
+  int &r; // expected-error {{instance variables cannot be of reference type}}
+}
+@end