From 57e07c950d858229249b362c0ae3b49401e40b17 Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Thu, 20 Nov 2014 22:06:44 +0000 Subject: [PATCH] Ensure all TypoExprs are diagnosed by the tree transform. 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). llvm-svn: 222465 --- clang/lib/Sema/SemaExprCXX.cpp | 16 ++++++++++++++++ clang/test/SemaCXX/typo-correction-delayed.cpp | 6 ++++++ clang/test/SemaTemplate/crash-10438657.cpp | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 94da5f2..35211a2 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5976,6 +5976,18 @@ static ExprResult attemptRecovery(Sema &SemaRef, } namespace { +class FindTypoExprs : public RecursiveASTVisitor { + llvm::SmallSetVector &TypoExprs; + +public: + explicit FindTypoExprs(llvm::SmallSetVector &TypoExprs) + : TypoExprs(TypoExprs) {} + bool VisitTypoExpr(TypoExpr *TE) { + TypoExprs.insert(TE); + return true; + } +}; + class TransformTypos : public TreeTransform { typedef TreeTransform 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; diff --git a/clang/test/SemaCXX/typo-correction-delayed.cpp b/clang/test/SemaCXX/typo-correction-delayed.cpp index c79fe45..984d68b 100644 --- a/clang/test/SemaCXX/typo-correction-delayed.cpp +++ b/clang/test/SemaCXX/typo-correction-delayed.cpp @@ -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'{{$}}}} +} diff --git a/clang/test/SemaTemplate/crash-10438657.cpp b/clang/test/SemaTemplate/crash-10438657.cpp index 3eaa8c1..2ee64bd 100644 --- a/clang/test/SemaTemplate/crash-10438657.cpp +++ b/clang/test/SemaTemplate/crash-10438657.cpp @@ -1,6 +1,6 @@ // RUN: not %clang_cc1 -fsyntax-only %s 2> %t // RUN: FileCheck %s < %t -// CHECK: 9 errors +// CHECK: 10 errors template class collate : public locale::facet { -- 2.7.4