diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index af576f817700a..2a195ff8537c4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -194,6 +194,7 @@ Bug Fixes to C++ Support - Fix the dynamic_cast to final class optimization to correctly handle casts that are guaranteed to fail (#GH137518). - Fix bug rejecting partial specialization of variable templates with auto NTTPs (#GH118190). +- Fix a crash when using ``explicit(bool)`` in pre-C++11 language modes. (#GH152729) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index d593d1d74d73d..ac64dd5c9c41f 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -6275,7 +6275,9 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From, QualType T, CCEKind CCE, NamedDecl *Dest, APValue &PreNarrowingValue) { - assert((S.getLangOpts().CPlusPlus11 || CCE == CCEKind::TempArgStrict) && + [[maybe_unused]] bool isCCEAllowedPreCXX11 = + (CCE == CCEKind::TempArgStrict || CCE == CCEKind::ExplicitBool); + assert((S.getLangOpts().CPlusPlus11 || isCCEAllowedPreCXX11) && "converted constant expression outside C++11 or TTP matching"); if (checkPlaceholderForOverload(S, From)) diff --git a/clang/test/Parser/explicit-bool-pre-cxx17.cpp b/clang/test/Parser/explicit-bool-pre-cxx17.cpp new file mode 100644 index 0000000000000..fee0889737a89 --- /dev/null +++ b/clang/test/Parser/explicit-bool-pre-cxx17.cpp @@ -0,0 +1,15 @@ +// Regression test for assertion failure when explicit(bool) is used in pre-C++20 +// Fixes GitHub issue #152729 +// RUN: %clang_cc1 -std=c++98 -verify %s +// RUN: %clang_cc1 -std=c++03 -verify %s +// RUN: %clang_cc1 -std=c++11 -verify %s +// RUN: %clang_cc1 -std=c++14 -verify %s +// RUN: %clang_cc1 -std=c++17 -verify %s + +struct S { + explicit(true) S(int); + // expected-warning@-1 {{explicit(bool) is a C++20 extension}} + + explicit(false) S(float); + // expected-warning@-1 {{explicit(bool) is a C++20 extension}} +};