public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113595] New: Confusing 'goto' is not a constant expression error message in constructor at compile time
@ 2024-01-25  8:10 hewillk at gmail dot com
  2024-01-25  8:17 ` [Bug c++/113595] [C++14/17]Confusing " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: hewillk at gmail dot com @ 2024-01-25  8:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113595
           Summary: Confusing 'goto' is not a constant expression error
                    message in constructor at compile time
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

template<int N>
struct MyArr {
  constexpr MyArr(const int (&arr)[N]) {
    for (int i = 0; i < N; i++)
      arr_[i] = arr[i];
  }
  int arr_[N];
};

constexpr int arr[10] = {};
constexpr MyArr<10> my_arr(arr);

https://godbolt.org/z/978rTjqGP

---------------

GCC correctly (I think) rejects the above code, but the error message is a bit
confusing:

<source>:4:5: error: 'goto' is not a constant expression
    4 |     for (int i = 0; i < N; i++)
      |     ^~~

since there is no 'goto' in the code.

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

* [Bug c++/113595] [C++14/17]Confusing 'goto' is not a constant expression error message in constructor at compile time
  2024-01-25  8:10 [Bug c++/113595] New: Confusing 'goto' is not a constant expression error message in constructor at compile time hewillk at gmail dot com
@ 2024-01-25  8:17 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-25  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-01-25
            Summary|Confusing 'goto' is not a   |[C++14/17]Confusing 'goto'
                   |constant expression error   |is not a constant
                   |message in constructor at   |expression error message in
                   |compile time                |constructor at compile time
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Also the message about goto is after the correct message already too:
```

<source>:3:13: note: 'constexpr MyArr<N>::MyArr(const int (&)[N]) [with int N =
10]' is not usable as a 'constexpr' function because:
    3 |   constexpr MyArr(const int (&arr)[N]) {
      |             ^~~~~
<source>:3:13: error: member 'MyArr<10>::arr_' must be initialized by
mem-initializer in 'constexpr' constructor
<source>:7:7: note: declared here
    7 |   int arr_[N];
      |       ^~~~
```

Interesting clang decides to accepts it (I suspect incorrect because MSVC
rejects it for the same reason as GCC) for C++14 and C++17.

Note for C++20, it is valid and GCC correctly accepts it.

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

end of thread, other threads:[~2024-01-25  8:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-25  8:10 [Bug c++/113595] New: Confusing 'goto' is not a constant expression error message in constructor at compile time hewillk at gmail dot com
2024-01-25  8:17 ` [Bug c++/113595] [C++14/17]Confusing " pinskia 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).