https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119282

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>:

https://gcc.gnu.org/g:9f523d49ada91050445f71821a9a06b0988402f5

commit r16-332-g9f523d49ada91050445f71821a9a06b0988402f5
Author: Patrick Palka <ppa...@redhat.com>
Date:   Thu May 1 11:40:44 2025 -0400

    c++: poor diag w/ non-constexpr dtor called from constexpr ctor

    When diagnosing a non-constexpr constructor call during constexpr
    evaluation, explain_invalid_constexpr_fn was passing the genericized
    body to require_potential_constant_expression rather than the saved
    non-genericized one.

    This meant for the below testcase (reduced from PR libstdc++/119282)
    in which B::B() is deemed non-constexpr due to the local variable having
    a non-constexpr destructor we would then issue the cryptic diagnostic:

    constexpr-nonlit19.C:17:16: error: non-constant condition for static
assertion
       17 | static_assert(f());
          |               ~^~
    constexpr-nonlit19.C:17:16:   in âconstexprâ expansion of âf()â
    constexpr-nonlit19.C:13:5: error: âconstexpr B::B()â called in a
constant expression
       13 |   B b;
          |     ^
    constexpr-nonlit19.C:6:13: note: âconstexpr B::B()â is not usable as a
âconstexprâ function because:
        6 |   constexpr B() {
          |             ^
    constexpr-nonlit19.C:8:5: error: âgotoâ is not a constant expression
        8 |     for (int i = 0; i < 10; i++) { }
          |     ^~~

    This patch makes us pass the non-genericized body to
    require_potential_constant_expression, and so we now emit:

    ...
    constexpr-nonlit19.C:6:13: note: âconstexpr B::B()â is not usable as a
âconstexprâ function because:
        6 |   constexpr B() {
          |             ^
    constexpr-nonlit19.C:9:3: error: call to non-âconstexprâ function
âA::~A()â
        9 |   }
          |   ^
    constexpr-nonlit19.C:3:12: note: âA::~A()â declared here
        3 | struct A { ~A() { } };
          |            ^

    gcc/cp/ChangeLog:

            * constexpr.cc (explain_invalid_constexpr_fn): In the
            DECL_CONSTRUCTOR_P branch pass the non-genericized body to
            require_potential_constant_expression.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp23/constexpr-nonlit19.C: New test.

    Reviewed-by: Jason Merrill <ja...@redhat.com>

Reply via email to