public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26
@ 2023-09-01 20:08 pkeir at outlook dot com
  2023-09-01 20:44 ` [Bug c++/111272] [13/14 Regression] " mpolacek at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: pkeir at outlook dot com @ 2023-09-01 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111272
           Summary: Truncated error messages with -std=c++23 and
                    -std=c++26
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pkeir at outlook dot com
  Target Milestone: ---

The C++14 code below requires the `constexpr` specifier on the `ft` member
function. Compiling this with `-std=c++14`, `-std=c++17` or `-std=c++20` will
provide a helpful error message which identifies the need to add the
`constexpr` specifier to `ft`.

However, if `-std=c++23`, or `-std=c++26` are used, no message indicating the
need for `constexpr` on `ft` is displayed; and the message itself is truncated:
ending only in "...not usable as a 'constexpr' function because:".

struct Jam
{
  // constexpr  // n.b.
  int ft() { return 42; }

  constexpr
  Jam() { ft(); }
};

constexpr bool test()
{
  Jam j;
  return true;
}

static_assert(test(), "");

The full truncated error message is:

$ /opt/gcc-latest/bin/g++ -std=c++26 -c truncated-constexpr-error-gcc.cpp 
truncated-constexpr-error-gcc.cpp:16:19: error: non-constant condition for
static assertion
   16 | static_assert(test(), "");
      |               ~~~~^~
truncated-constexpr-error-gcc.cpp:16:19:   in ‘constexpr’ expansion of ‘test()’
truncated-constexpr-error-gcc.cpp:12:7: error: ‘constexpr Jam::Jam()’ called in
a constant expression
   12 |   Jam j;
      |       ^
truncated-constexpr-error-gcc.cpp:7:3: note: ‘constexpr Jam::Jam()’ is not
usable as a ‘constexpr’ function because:
    7 |   Jam() { ft(); }
      |   ^~~

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
@ 2023-09-01 20:44 ` mpolacek at gcc dot gnu.org
  2023-09-01 22:48 ` pkeir at outlook dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-09-01 20:44 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
            Summary|Truncated error messages    |[13/14 Regression]
                   |with -std=c++23 and         |Truncated error messages
                   |-std=c++26                  |with -std=c++23 and
                   |                            |-std=c++26
   Last reconfirmed|                            |2023-09-01
   Target Milestone|---                         |13.3
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
           Keywords|                            |diagnostic

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r13-4112-gc85f8dbb173f45:

commit c85f8dbb173f45053f6d8849d27adc98d9668769
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Nov 2 13:11:02 2022 -0400

    c++: P2448 - Relaxing some constexpr restrictions [PR106649]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
  2023-09-01 20:44 ` [Bug c++/111272] [13/14 Regression] " mpolacek at gcc dot gnu.org
@ 2023-09-01 22:48 ` pkeir at outlook dot com
  2023-09-04 10:50 ` de34 at live dot cn
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pkeir at outlook dot com @ 2023-09-01 22:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Paul Keir <pkeir at outlook dot com> ---
Thanks. The `-Winvalid-constexpr` mentioned there is a helpful workaround.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
  2023-09-01 20:44 ` [Bug c++/111272] [13/14 Regression] " mpolacek at gcc dot gnu.org
  2023-09-01 22:48 ` pkeir at outlook dot com
@ 2023-09-04 10:50 ` de34 at live dot cn
  2023-09-12 18:28 ` pkeir at outlook dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: de34 at live dot cn @ 2023-09-04 10:50 UTC (permalink / raw)
  To: gcc-bugs

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

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #3 from Jiang An <de34 at live dot cn> ---
Due to P2448R2 (https://wg21.link/p2448r2), the posted example is totally valid
since C++23.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
                   ` (2 preceding siblings ...)
  2023-09-04 10:50 ` de34 at live dot cn
@ 2023-09-12 18:28 ` pkeir at outlook dot com
  2023-09-14 14:16 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pkeir at outlook dot com @ 2023-09-12 18:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paul Keir <pkeir at outlook dot com> ---
I believe P2448R2 would only allow the code, without the static_assert.
Explicitly calling `test()`, `Jam::Jam()` and then `Jam::ft()` here would mean
evaluating a non-constexpr function (i.e. `ft`). ft is *constexpr-suitable*,
but still needs the `constexpr` specifier when it is constant evaluated.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
                   ` (3 preceding siblings ...)
  2023-09-12 18:28 ` pkeir at outlook dot com
@ 2023-09-14 14:16 ` mpolacek at gcc dot gnu.org
  2023-10-16 12:33 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-09-14 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Paul Keir from comment #4)
> I believe P2448R2 would only allow the code, without the static_assert.
> Explicitly calling `test()`, `Jam::Jam()` and then `Jam::ft()` here would
> mean evaluating a non-constexpr function (i.e. `ft`). ft is
> *constexpr-suitable*, but still needs the `constexpr` specifier when it is
> constant evaluated.

I agree.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
                   ` (4 preceding siblings ...)
  2023-09-14 14:16 ` mpolacek at gcc dot gnu.org
@ 2023-10-16 12:33 ` cvs-commit at gcc dot gnu.org
  2023-10-16 12:35 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-16 12:33 UTC (permalink / raw)
  To: gcc-bugs

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 <mpolacek@gcc.gnu.org>:

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

commit r14-4659-ga22eeaca5ce753a0a3c22013ee3ecde04c71c2f4
Author: Marek Polacek <polacek@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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
                   ` (5 preceding siblings ...)
  2023-10-16 12:33 ` cvs-commit at gcc dot gnu.org
@ 2023-10-16 12:35 ` mpolacek at gcc dot gnu.org
  2024-01-12 18:07 ` pkeir at outlook dot com
  2024-01-12 19:14 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-10-16 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
                   ` (6 preceding siblings ...)
  2023-10-16 12:35 ` mpolacek at gcc dot gnu.org
@ 2024-01-12 18:07 ` pkeir at outlook dot com
  2024-01-12 19:14 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pkeir at outlook dot com @ 2024-01-12 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Paul Keir <pkeir at outlook dot com> ---
I wonder if a small part of this bug still remains. The code below should
#include <initializer_list>, but as it doesn't, we get an error message. The
message now gives all the right information but, with -std=c++23 and
-std=c++26, a part of the text is still truncated. Instead of "declared here"
we get "is not usable as a 'constexpr' function because:". Perhaps it should
also say "declared here" with -std=c++23 and -std=c++26.

At https://godbolt.org/z/6c9hME7hh the code is:

// #include <initializer_list>

constexpr bool init_list()
{
  int total{};
  for (int x : {1, 2, 3})
    total += x;
  return total == 6;
}

static_assert(init_list(), "");

The error message is:

<source>: In function 'constexpr bool init_list()':
<source>:6:24: error: deducing from brace-enclosed initializer list requires
'#include <initializer_list>'
  +++ |+#include <initializer_list>
    1 | // #include <initializer_list>
......
    6 |   for (int x : {1, 2, 3})
      |                        ^
<source>: At global scope:
<source>:11:24: error: non-constant condition for static assertion
   11 | static_assert(init_list(), "");
      |               ~~~~~~~~~^~
<source>:11:24: error: 'constexpr bool init_list()' called in a constant
expression
<source>:3:16: note: 'constexpr bool init_list()' is not usable as a
'constexpr' function because:
    3 | constexpr bool init_list()
      |                ^~~~~~~~~
Compiler returned: 1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111272] [13/14 Regression] Truncated error messages with -std=c++23 and -std=c++26
  2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
                   ` (7 preceding siblings ...)
  2024-01-12 18:07 ` pkeir at outlook dot com
@ 2024-01-12 19:14 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-12 19:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Paul Keir from comment #8)
> I wonder if a small part of this bug still remains.

You're right, there's still something bad.  I've opened bug 113360 for it.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-12 19:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-01 20:08 [Bug c++/111272] New: Truncated error messages with -std=c++23 and -std=c++26 pkeir at outlook dot com
2023-09-01 20:44 ` [Bug c++/111272] [13/14 Regression] " mpolacek at gcc dot gnu.org
2023-09-01 22:48 ` pkeir at outlook dot com
2023-09-04 10:50 ` de34 at live dot cn
2023-09-12 18:28 ` pkeir at outlook dot com
2023-09-14 14:16 ` mpolacek at gcc dot gnu.org
2023-10-16 12:33 ` cvs-commit at gcc dot gnu.org
2023-10-16 12:35 ` mpolacek at gcc dot gnu.org
2024-01-12 18:07 ` pkeir at outlook dot com
2024-01-12 19:14 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).