public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97234] New: Constexpr class-scope array initializer referencing previous elements
@ 2020-09-29  1:09 botond at mozilla dot com
  2021-08-17  5:23 ` [Bug c++/97234] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: botond at mozilla dot com @ 2020-09-29  1:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97234
           Summary: Constexpr class-scope array initializer referencing
                    previous elements
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: botond at mozilla dot com
  Target Milestone: ---

The following code:

struct S {
    static constexpr int rolling_sum[4]{
        0,
        rolling_sum[0] + 1,
        rolling_sum[1] + 2,
        rolling_sum[2] + 3
    };
};

produces errors when compiled with g++ 10:

test.cpp:4:9: error: ‘rolling_sum’ was not declared in this scope
    4 |         rolling_sum[0] + 1,
      |         ^~~~~~~~~~~
test.cpp:5:9: error: ‘rolling_sum’ was not declared in this scope
    5 |         rolling_sum[1] + 2,
      |         ^~~~~~~~~~~
test.cpp:6:9: error: ‘rolling_sum’ was not declared in this scope
    6 |         rolling_sum[2] + 3
      |   

The code is accepted by clang. It's also accepted by gcc if the array is
declared at namespace scope, leading me to believe that rejecting it at class
scope is likely a bug.

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

* [Bug c++/97234] Constexpr class-scope array initializer referencing previous elements
  2020-09-29  1:09 [Bug c++/97234] New: Constexpr class-scope array initializer referencing previous elements botond at mozilla dot com
@ 2021-08-17  5:23 ` pinskia at gcc dot gnu.org
  2021-08-17  5:40 ` botond at mozilla dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-17  5:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
ICC and MSVC reject it similar to GCC even.  Are you sure this is valid?

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

* [Bug c++/97234] Constexpr class-scope array initializer referencing previous elements
  2020-09-29  1:09 [Bug c++/97234] New: Constexpr class-scope array initializer referencing previous elements botond at mozilla dot com
  2021-08-17  5:23 ` [Bug c++/97234] " pinskia at gcc dot gnu.org
@ 2021-08-17  5:40 ` botond at mozilla dot com
  2021-08-17 19:43 ` botond at mozilla dot com
  2021-08-17 19:56 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: botond at mozilla dot com @ 2021-08-17  5:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Botond Ballo <botond at mozilla dot com> ---
I believe it's valid because the point of declaration of a variable is just
before its initializer
(https://timsong-cpp.github.io/cppwp/n4861/basic.scope.pdecl#1), and thus the
variable should be in scope in its initializer.

But I'm not a wording expert and it's possible I'm mistaken, or overlooking
something else that would make this invalid.

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

* [Bug c++/97234] Constexpr class-scope array initializer referencing previous elements
  2020-09-29  1:09 [Bug c++/97234] New: Constexpr class-scope array initializer referencing previous elements botond at mozilla dot com
  2021-08-17  5:23 ` [Bug c++/97234] " pinskia at gcc dot gnu.org
  2021-08-17  5:40 ` botond at mozilla dot com
@ 2021-08-17 19:43 ` botond at mozilla dot com
  2021-08-17 19:56 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: botond at mozilla dot com @ 2021-08-17 19:43 UTC (permalink / raw)
  To: gcc-bugs

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

Botond Ballo <botond at mozilla dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=99059

--- Comment #3 from Botond Ballo <botond at mozilla dot com> ---
Bug 99059 is similar (involving C++17 "inline" rather than constexpr) and
Jonathan Wakely said it's a bug.

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

* [Bug c++/97234] Constexpr class-scope array initializer referencing previous elements
  2020-09-29  1:09 [Bug c++/97234] New: Constexpr class-scope array initializer referencing previous elements botond at mozilla dot com
                   ` (2 preceding siblings ...)
  2021-08-17 19:43 ` botond at mozilla dot com
@ 2021-08-17 19:56 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-17 19:56 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-08-17

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, I think this one is too.

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

end of thread, other threads:[~2021-08-17 19:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29  1:09 [Bug c++/97234] New: Constexpr class-scope array initializer referencing previous elements botond at mozilla dot com
2021-08-17  5:23 ` [Bug c++/97234] " pinskia at gcc dot gnu.org
2021-08-17  5:40 ` botond at mozilla dot com
2021-08-17 19:43 ` botond at mozilla dot com
2021-08-17 19:56 ` redi 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).