From: Reid Kleckner Date: Sat, 13 Dec 2014 00:53:10 +0000 (+0000) Subject: Typo correction: Ignore temporary binding exprs after overload resolution X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb1f68b69544b4d7895251fc4dbb9dafbc1a8e67;p=clang Typo correction: Ignore temporary binding exprs after overload resolution Transformation of a CallExpr doesn't always result in a new CallExpr. Fixes PR21899. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224172 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index e8be716ea0..554e8c9b8f 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -6105,8 +6105,13 @@ public: auto Result = BaseTransform::RebuildCallExpr(Callee, LParenLoc, Args, RParenLoc, ExecConfig); if (auto *OE = dyn_cast(Callee)) { - if (!Result.isInvalid() && Result.get()) - OverloadResolution[OE] = cast(Result.get())->getCallee(); + if (!Result.isInvalid() && Result.get()) { + Expr *ResultCall = Result.get(); + if (auto *BE = dyn_cast(ResultCall)) + ResultCall = BE->getSubExpr(); + if (auto *CE = dyn_cast(ResultCall)) + OverloadResolution[OE] = CE->getCallee(); + } } return Result; } diff --git a/test/SemaCXX/typo-correction-delayed.cpp b/test/SemaCXX/typo-correction-delayed.cpp index d303b58554..d42888f1e6 100644 --- a/test/SemaCXX/typo-correction-delayed.cpp +++ b/test/SemaCXX/typo-correction-delayed.cpp @@ -119,3 +119,23 @@ class SomeClass { public: explicit SomeClass() : Kind(kSum) {} // expected-error {{use of undeclared identifier 'kSum'; did you mean 'kNum'?}} }; + +extern "C" int printf(const char *, ...); + +// There used to be an issue with typo resolution inside overloads. +struct AssertionResult { + ~AssertionResult(); + operator bool(); + int val; +}; +AssertionResult Compare(const char *a, const char *b); +AssertionResult Compare(int a, int b); +int main() { + // expected-note@+1 {{'result' declared here}} + const char *result; + // expected-error@+1 {{use of undeclared identifier 'resulta'; did you mean 'result'?}} + if (AssertionResult ar = (Compare("value1", resulta))) + ; + else + printf("ar: %d\n", ar.val); +}