r264444 - [ObjCXX] Warn undeclared identifiers.

Manman Ren via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 11:43:46 PDT 2016


Author: mren
Date: Fri Mar 25 13:43:46 2016
New Revision: 264444

URL: http://llvm.org/viewvc/llvm-project?rev=264444&view=rev
Log:
[ObjCXX] Warn undeclared identifiers.

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. It
also propagates the other instantiation bits.

rdar://24975562

Differential Revision: http://reviews.llvm.org/D18461

Added:
    cfe/trunk/test/SemaObjCXX/typo-correction.mm
Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=264444&r1=264443&r2=264444&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Mar 25 13:43:46 2016
@@ -847,10 +847,12 @@ public:
                   ExprObjectKind OK = OK_Ordinary,
                   Expr *SourceExpr = nullptr)
     : Expr(OpaqueValueExprClass, T, VK, OK,
-           T->isDependentType(), 
+           T->isDependentType() ||
+           (SourceExpr && SourceExpr->isTypeDependent()),
            T->isDependentType() || 
            (SourceExpr && SourceExpr->isValueDependent()),
-           T->isInstantiationDependentType(),
+           T->isInstantiationDependentType() ||
+           (SourceExpr && SourceExpr->isInstantiationDependent()),
            false),
       SourceExpr(SourceExpr), Loc(Loc) {
   }

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=264444&r1=264443&r2=264444&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Mar 25 13:43:46 2016
@@ -115,6 +115,7 @@ protected:
     friend class OverloadExpr; // ctor
     friend class PseudoObjectExpr; // ctor
     friend class AtomicExpr; // ctor
+    friend class OpaqueValueExpr; // ctor
     unsigned : NumStmtBits;
 
     unsigned ValueKind : 2;

Added: cfe/trunk/test/SemaObjCXX/typo-correction.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/typo-correction.mm?rev=264444&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/typo-correction.mm (added)
+++ cfe/trunk/test/SemaObjCXX/typo-correction.mm Fri Mar 25 13:43:46 2016
@@ -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




More information about the cfe-commits mailing list