[Bug c++/124404] __builtin_constexpr_diag() doesn't work with non-PODs (like std::string)

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Mar 11 06:53:03 GMT 2026


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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:eb908945226a63acfd215dac11b7f686f769636d

commit r16-7995-geb908945226a63acfd215dac11b7f686f769636d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 11 07:50:22 2026 +0100

    c++: Fix up __builtin_constexpr_diag for std::string operands [PR124404]

    __builtin_constexpr_diag works fine with string literals or class arguments
    like std::{,u8}string_view or string view like classes, but as the
following
    testcase shows doesn't work with std::string argument.
    I believe the important difference is that std::string has non-trivial
    destructor and so needs to be passed by invisible reference while
    std::string_view doesn't.

    Anyway, the following patch makes it work even with std::string.

    2026-03-11  Jakub Jelinek  <jakub@redhat.com>

            PR c++/124404
            * constexpr.cc (cxx_eval_constexpr_diag): Call
convert_from_reference
            on arguments.

            * g++.dg/ext/constexpr-diag7.C: New test.

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


More information about the Gcc-bugs mailing list