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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>:

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

commit r14-4659-ga22eeaca5ce753a0a3c22013ee3ecde04c71c2f4
Author: Marek Polacek <pola...@redhat.com>
Date:   Fri Oct 13 16:47:47 2023 -0400

    c++: fix truncated diagnostic in C++23 [PR111272]

    In C++23, since P2448, a constexpr function F that calls a non-constexpr
    function N is OK as long as we don't actually call F in a constexpr
    context.  So instead of giving an error in maybe_save_constexpr_fundef,
    we only give an error when evaluating the call.  Unfortunately, as shown
    in this PR, the diagnostic can be truncated:

    z.C:10:13: note: 'constexpr Jam::Jam()' is not usable as a 'constexpr'
function because:
       10 |   constexpr Jam() { ft(); }
          |             ^~~

    ...because what?  With this patch, we say:

    z.C:10:13: note: 'constexpr Jam::Jam()' is not usable as a 'constexpr'
function because:
       10 |   constexpr Jam() { ft(); }
          |             ^~~
    z.C:10:23: error: call to non-'constexpr' function 'int Jam::ft()'
       10 |   constexpr Jam() { ft(); }
          |                     ~~^~
    z.C:8:7: note: 'int Jam::ft()' declared here
        8 |   int ft() { return 42; }
          |       ^~

    Like maybe_save_constexpr_fundef, explain_invalid_constexpr_fn should
    also check the body of a constructor, not just the mem-initializer.

            PR c++/111272

    gcc/cp/ChangeLog:

            * constexpr.cc (explain_invalid_constexpr_fn): Also check the body
of
            a constructor in C++14 and up.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/constexpr-diag1.C: New test.
  • [Bug c++/111272] [13/14 Regress... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to