]> granicus.if.org Git - clang/commitdiff
Ensure all TypoExprs are diagnosed by the tree transform.
authorKaelyn Takata <rikka@google.com>
Thu, 20 Nov 2014 22:06:44 +0000 (22:06 +0000)
committerKaelyn Takata <rikka@google.com>
Thu, 20 Nov 2014 22:06:44 +0000 (22:06 +0000)
If there is more than one TypoExpr within the expr being transformed and
any but the last TypoExpr seen don't have any viable candidates, the
tree transform will be aborted early and the remaining TypoExprs are
never seen and hence never diagnosed. This adds a simple
RecursiveASTVisitor to find all of the TypoExprs to be diagnosed in the
case where typo correction of the entire expr fails (and the result of
the tree transform is an ExprError).

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

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/typo-correction-delayed.cpp
test/SemaTemplate/crash-10438657.cpp

index 94da5f22d667c34d54d909b260ee181ee96c43dc..35211a28a52462bbe3597b8696b5609b98df49cd 100644 (file)
@@ -5976,6 +5976,18 @@ static ExprResult attemptRecovery(Sema &SemaRef,
 }
 
 namespace {
+class FindTypoExprs : public RecursiveASTVisitor<FindTypoExprs> {
+  llvm::SmallSetVector<TypoExpr *, 2> &TypoExprs;
+
+public:
+  explicit FindTypoExprs(llvm::SmallSetVector<TypoExpr *, 2> &TypoExprs)
+      : TypoExprs(TypoExprs) {}
+  bool VisitTypoExpr(TypoExpr *TE) {
+    TypoExprs.insert(TE);
+    return true;
+  }
+};
+
 class TransformTypos : public TreeTransform<TransformTypos> {
   typedef TreeTransform<TransformTypos> BaseTransform;
 
@@ -6084,6 +6096,10 @@ public:
         break;
     }
 
+    // Ensure that all of the TypoExprs within the current Expr have been found.
+    if (!res.isUsable())
+      FindTypoExprs(TypoExprs).TraverseStmt(E);
+
     EmitAllDiagnostics();
 
     return res;
index c79fe45629fc8d0f1f00bb08fd4801f67792f606..984d68b6b9254174a661ba094328f90dc540676c 100644 (file)
@@ -42,3 +42,9 @@ public:
 void testMemberExpr(Foo *f) {
   f->TestIt();  // expected-error {{no member named 'TestIt' in 'Foo'; did you mean 'textIt'?}}
 }
+
+void callee(double, double);
+void testNoCandidates() {
+  callee(xxxxxx,   // expected-error-re {{use of undeclared identifier 'xxxxxx'{{$}}}}
+         zzzzzz);  // expected-error-re {{use of undeclared identifier 'zzzzzz'{{$}}}}
+}
index 3eaa8c1ea7d998985b3d33fb09cd737d52313ca2..2ee64bdfcdbbb24705d023d98c1c288fba0f66fd 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: not %clang_cc1 -fsyntax-only %s 2> %t
 // RUN: FileCheck %s < %t
-// CHECK: 9 errors
+// CHECK: 10 errors
 template<typename _CharT>
 class collate : public locale::facet {