diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ecdbbc05cdef4..4bc5a30440b3c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -623,6 +623,7 @@ Bug Fixes to C++ Support - Fix the result of ``__is_pointer_interconvertible_base_of`` when arguments are qualified and passed via template parameters. (#GH135273) - Fixed a crash when evaluating nested requirements in requires-expressions that reference invented parameters. (#GH166325) - Fixed a crash when standard comparison categories (e.g. ``std::partial_ordering``) are defined with incorrect static member types. (#GH170015) (#GH56571) +- Fixed an assertion failure in floating conversion narrowing caused by C++ constant expression checks in C23 mode. (#GH173847) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index bc3cfe7ef9a0c..aa563f772c89e 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -449,7 +449,8 @@ NarrowingKind StandardConversionSequence::getNarrowingKind( Expr::EvalResult R; if ((Ctx.getLangOpts().C23 && Initializer->EvaluateAsRValue(R, Ctx)) || - Initializer->isCXX11ConstantExpr(Ctx, &ConstantValue)) { + ((Ctx.getLangOpts().CPlusPlus && + Initializer->isCXX11ConstantExpr(Ctx, &ConstantValue)))) { // Constant! if (Ctx.getLangOpts().C23) ConstantValue = R.Val; diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c index e9b738ab4d190..16255c264423a 100644 --- a/clang/test/Sema/constexpr.c +++ b/clang/test/Sema/constexpr.c @@ -401,3 +401,11 @@ bool issue155507(v2int16_t a, v2int16_t b) { constexpr bool b2 = (bool)nullptr; _Static_assert(!b2); + +double ghissue173847(double a) { + double result = 3.0 / (a + 4.5 - 2.1 * 0.7); + return result; +} +void ghissue173847_test() { + constexpr float f_const = ghissue173847(2.0); // expected-error {{constexpr variable 'f_const' must be initialized by a constant expression}} +}