[PATCH] D18461: ObjCXX: Warn undeclared identifiers.

Manman Ren via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 13:43:46 PDT 2016


manmanren created this revision.
manmanren added reviewers: rsmith, rjmccall.
manmanren added a subscriber: cfe-commits.

Instantiation dependence were not being handled correctly for OpqaueValueExpr
AST nodes. As a result, if an undeclared identifier was used in a CXXNewExpr
that is assigned to a ObjC property, there would be no error during parsing, and
there would be a crash during code gen. This patch makes sure that an error
will be issued during parsing in this case.

Before the fix, if CXXNewExpr has a typo, its InstantiationDependent will be
set to true, but if it is wrapped in a OpaqueValueExpr, the OpaqueValueExpr will
not be instantiation dependent, causing the TypoExpr not be to resolved. The fix
propagates InstantiationDependent to OpaqueValueExpr from its SourceExpr.

http://reviews.llvm.org/D18461

Files:
  include/clang/AST/Expr.h
  include/clang/AST/Stmt.h
  test/SemaObjCXX/typo-correction.mm

Index: test/SemaObjCXX/typo-correction.mm
===================================================================
--- /dev/null
+++ test/SemaObjCXX/typo-correction.mm
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+class ClassA {};
+
+class ClassB {
+public:
+  ClassB(ClassA* parent=0);
+  ~ClassB();
+};
+
+ at interface NSObject
+ at end
+
+ at interface InterfaceA : NSObject
+ at property(nonatomic, assign) ClassA *m_prop1; // expected-note {{here}}
+ at property(nonatomic, assign) ClassB *m_prop2;
+ at end
+
+ at implementation InterfaceA
+- (id)test {
+  self.m_prop2 = new ClassB(m_prop1); // expected-error {{use of undeclared identifier 'm_prop1'; did you mean '_m_prop1'?}}
+}
+ at end
Index: include/clang/AST/Stmt.h
===================================================================
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -115,6 +115,7 @@
     friend class OverloadExpr; // ctor
     friend class PseudoObjectExpr; // ctor
     friend class AtomicExpr; // ctor
+    friend class OpaqueValueExpr; // ctor
     unsigned : NumStmtBits;
 
     unsigned ValueKind : 2;
Index: include/clang/AST/Expr.h
===================================================================
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -853,6 +853,8 @@
            T->isInstantiationDependentType(),
            false),
       SourceExpr(SourceExpr), Loc(Loc) {
+    if (SourceExpr)
+      ExprBits.InstantiationDependent |= SourceExpr->isInstantiationDependent();
   }
 
   /// Given an expression which invokes a copy constructor --- i.e.  a


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18461.51598.patch
Type: text/x-patch
Size: 1561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160324/ad8dc9a2/attachment.bin>


More information about the cfe-commits mailing list