https://github.com/jongmyeong-choi created https://github.com/llvm/llvm-project/pull/152985
Allow CCEKind::ExplicitBool in BuildConvertedConstantExpression for pre-C++11 contexts, similar to the existing TempArgStrict exception. This enables explicit(bool) to work as a C++20 extension in earlier language modes without triggering assertion failures. Fixes #152729 >From 45df017304094708841fadd23b6971f348d229bd Mon Sep 17 00:00:00 2001 From: Jongmyeong Choi <cheesec...@gmail.com> Date: Mon, 11 Aug 2025 18:36:30 +0900 Subject: [PATCH] [clang] Fix assertion failure with explicit(bool) in pre-C++11 modes Allow CCEKind::ExplicitBool in BuildConvertedConstantExpression for pre-C++11 contexts, similar to the existing TempArgStrict exception. This enables explicit(bool) to work as a C++20 extension in earlier language modes without triggering assertion failures. Fixes #152729 --- clang/lib/Sema/SemaOverload.cpp | 4 +++- clang/test/Parser/explicit-bool-pre-cxx17.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 clang/test/Parser/explicit-bool-pre-cxx17.cpp diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 5dd5b495480d9..700c330f02427 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -6268,7 +6268,9 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From, QualType T, CCEKind CCE, NamedDecl *Dest, APValue &PreNarrowingValue) { - assert((S.getLangOpts().CPlusPlus11 || CCE == CCEKind::TempArgStrict) && + 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..0a704f3ef85cd --- /dev/null +++ b/clang/test/Parser/explicit-bool-pre-cxx17.cpp @@ -0,0 +1,14 @@ +// Regression test for assertion failure when explicit(bool) is used in pre-C++20 +// Fixes GitHub issue #152729 +// 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}} +}; \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits