diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -294,6 +294,8 @@ not a type concept. - Fix crash when a doc comment contains a line splicing. (`#62054 `_) +- Fix crash after suggesting typo correction to constexpr if condition. + (`#61885 `_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -12851,7 +12851,8 @@ bool IsConstexpr) : ConditionVar(ConditionVar), Condition(Condition), Invalid(false), HasKnownValue(IsConstexpr && Condition.get() && - !Condition.get()->isValueDependent()), + !Condition.get()->isValueDependent() && + Condition.get()->isIntegerConstantExpr(S.Context)), KnownValue(HasKnownValue && !!Condition.get()->EvaluateKnownConstInt(S.Context)) {} explicit ConditionResult(bool Invalid) diff --git a/clang/test/SemaCXX/invalid-if-constexpr.cpp b/clang/test/SemaCXX/invalid-if-constexpr.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/invalid-if-constexpr.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -verify -std=c++20 %s + +namespace GH61885 { +void similar() { // expected-note {{'similar' declared here}} + if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 'similer'; did you mean 'similar'?}} +} +void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \ + // expected-note {{'__sync_swap' declared here}} + +int AA() { return true;} // expected-note {{'AA' declared here}} + +void b() { if constexpr (AAA<>) {}} // expected-error {{use of undeclared identifier 'AAA'; did you mean 'AA'?}} +} +