]> granicus.if.org Git - clang/commitdiff
[ObjCXX] Warn undeclared identifiers.
authorManman Ren <manman.ren@gmail.com>
Fri, 25 Mar 2016 18:43:46 +0000 (18:43 +0000)
committerManman Ren <manman.ren@gmail.com>
Fri, 25 Mar 2016 18:43:46 +0000 (18:43 +0000)
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

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

include/clang/AST/Expr.h
include/clang/AST/Stmt.h
test/SemaObjCXX/typo-correction.mm [new file with mode: 0644]

index bc5dab754c671df876d2dbe3553d29f37c30bc20..6b14c60e9513bbac42c29b7dd94557dc419820b3 100644 (file)
@@ -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) {
   }
index d3950e92cf0d78dbccb1c38020909d8d3e604aad..b6ed6c547cc4c5965ab96a3df84d0976c4915aa0 100644 (file)
@@ -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;
diff --git a/test/SemaObjCXX/typo-correction.mm b/test/SemaObjCXX/typo-correction.mm
new file mode 100644 (file)
index 0000000..a34a790
--- /dev/null
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+class ClassA {};
+
+class ClassB {
+public:
+  ClassB(ClassA* parent=0);
+  ~ClassB();
+};
+
+@interface NSObject
+@end
+
+@interface InterfaceA : NSObject
+@property(nonatomic, assign) ClassA *m_prop1; // expected-note {{here}}
+@property(nonatomic, assign) ClassB *m_prop2;
+@end
+
+@implementation InterfaceA
+- (id)test {
+  self.m_prop2 = new ClassB(m_prop1); // expected-error {{use of undeclared identifier 'm_prop1'; did you mean '_m_prop1'?}}
+}
+@end