Skip to content

Commit 44531c6

Browse files
author
Jongmyeong Choi
committed
[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
1 parent 48beed5 commit 44531c6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/SemaOverload.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6275,7 +6275,9 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
62756275
QualType T, CCEKind CCE,
62766276
NamedDecl *Dest,
62776277
APValue &PreNarrowingValue) {
6278-
assert((S.getLangOpts().CPlusPlus11 || CCE == CCEKind::TempArgStrict) &&
6278+
bool isCCEAllowedPreCXX11 =
6279+
(CCE == CCEKind::TempArgStrict || CCE == CCEKind::ExplicitBool);
6280+
assert((S.getLangOpts().CPlusPlus11 || isCCEAllowedPreCXX11) &&
62796281
"converted constant expression outside C++11 or TTP matching");
62806282

62816283
if (checkPlaceholderForOverload(S, From))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for assertion failure when explicit(bool) is used in pre-C++20
2+
// Fixes GitHub issue #152729
3+
// RUN: %clang_cc1 -std=c++03 -verify %s
4+
// RUN: %clang_cc1 -std=c++11 -verify %s
5+
// RUN: %clang_cc1 -std=c++14 -verify %s
6+
// RUN: %clang_cc1 -std=c++17 -verify %s
7+
8+
struct S {
9+
explicit(true) S(int);
10+
// expected-warning@-1 {{explicit(bool) is a C++20 extension}}
11+
12+
explicit(false) S(float);
13+
// expected-warning@-1 {{explicit(bool) is a C++20 extension}}
14+
};

0 commit comments

Comments
 (0)