public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers
@ 2024-01-29 14:18 bugdal at aerifal dot cx
  2024-01-29 14:19 ` [Bug c/113653] " bugdal at aerifal dot cx
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: bugdal at aerifal dot cx @ 2024-01-29 14:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113653
           Summary: Failure to diagnose use of (non-constant-expr) const
                    objects in static initializers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx
  Target Milestone: ---

The following is a constraint violation:

int foo()
{
    static const int x = 1;
    static const int y = x; // not a constant expression
    return y;
}

However, gcc does not diagnose it as such, even with -Wall -Wextra.

This appears to have been a regression somewhere between the gcc 4 era and now.

I'm not sure what component this should be assigned to. I chose "c" because
it's C-specific that this is not a constant expression; it would be in C++.

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

* [Bug c/113653] Failure to diagnose use of (non-constant-expr) const objects in static initializers
  2024-01-29 14:18 [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers bugdal at aerifal dot cx
@ 2024-01-29 14:19 ` bugdal at aerifal dot cx
  2024-01-29 16:44 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bugdal at aerifal dot cx @ 2024-01-29 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Rich Felker <bugdal at aerifal dot cx> ---
FWIW -pedantic also does not help.

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

* [Bug c/113653] Failure to diagnose use of (non-constant-expr) const objects in static initializers
  2024-01-29 14:18 [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers bugdal at aerifal dot cx
  2024-01-29 14:19 ` [Bug c/113653] " bugdal at aerifal dot cx
@ 2024-01-29 16:44 ` pinskia at gcc dot gnu.org
  2024-01-29 16:46 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-29 16:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This was done on purpose, see PR 83222 (and PR 69960).

*** This bug has been marked as a duplicate of bug 83222 ***

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

* [Bug c/113653] Failure to diagnose use of (non-constant-expr) const objects in static initializers
  2024-01-29 14:18 [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers bugdal at aerifal dot cx
  2024-01-29 14:19 ` [Bug c/113653] " bugdal at aerifal dot cx
  2024-01-29 16:44 ` pinskia at gcc dot gnu.org
@ 2024-01-29 16:46 ` pinskia at gcc dot gnu.org
  2024-01-29 16:52 ` bugdal at aerifal dot cx
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-29 16:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Specifically https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69960#c24 .

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

* [Bug c/113653] Failure to diagnose use of (non-constant-expr) const objects in static initializers
  2024-01-29 14:18 [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers bugdal at aerifal dot cx
                   ` (2 preceding siblings ...)
  2024-01-29 16:46 ` pinskia at gcc dot gnu.org
@ 2024-01-29 16:52 ` bugdal at aerifal dot cx
  2024-01-29 16:55 ` pinskia at gcc dot gnu.org
  2024-01-29 17:12 ` bugdal at aerifal dot cx
  5 siblings, 0 replies; 7+ messages in thread
From: bugdal at aerifal dot cx @ 2024-01-29 16:52 UTC (permalink / raw)
  To: gcc-bugs

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

Rich Felker <bugdal at aerifal dot cx> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |---
             Status|RESOLVED                    |UNCONFIRMED

--- Comment #4 from Rich Felker <bugdal at aerifal dot cx> ---
This is NOT a duplicate of the marked bug - that bug was complaining that
invalid code didn't compile.

This bug is that GCC accepts invalid code, even with -pedantic, with no
diagnostic, making it impossible to catch invalid C. This bug bit me in the
wild - I accepted code that should have been rejected as a constraint
violation, and thereby made the project impossible to compile with other
compilers for a couple releases.

In standards-conforming and/or pedantic mode, the code should be rejected.

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

* [Bug c/113653] Failure to diagnose use of (non-constant-expr) const objects in static initializers
  2024-01-29 14:18 [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers bugdal at aerifal dot cx
                   ` (3 preceding siblings ...)
  2024-01-29 16:52 ` bugdal at aerifal dot cx
@ 2024-01-29 16:55 ` pinskia at gcc dot gnu.org
  2024-01-29 17:12 ` bugdal at aerifal dot cx
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-29 16:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Specifically https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69960#c24 .

See that comment. It explains on why this is not exactly invalid code.

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

* [Bug c/113653] Failure to diagnose use of (non-constant-expr) const objects in static initializers
  2024-01-29 14:18 [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers bugdal at aerifal dot cx
                   ` (4 preceding siblings ...)
  2024-01-29 16:55 ` pinskia at gcc dot gnu.org
@ 2024-01-29 17:12 ` bugdal at aerifal dot cx
  5 siblings, 0 replies; 7+ messages in thread
From: bugdal at aerifal dot cx @ 2024-01-29 17:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Rich Felker <bugdal at aerifal dot cx> ---
I'm aware of the allowance to accept "other forms". It's unfortunately
underspecified (does the implementation need to be specific in what forms?
document them per the normal rules for implementation-defined behavior? etc.)
but indeed it exists.

Regardless, at least -pedantic should diagnose this, because it's a big footgun
for writing code that is not valid C, that only works with certain compilers
that implement C++-like behavior in C. I would also be happy with a separate
warning option controlling it, named something like like
-Wextended-constant-expressions.

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 14:18 [Bug c/113653] New: Failure to diagnose use of (non-constant-expr) const objects in static initializers bugdal at aerifal dot cx
2024-01-29 14:19 ` [Bug c/113653] " bugdal at aerifal dot cx
2024-01-29 16:44 ` pinskia at gcc dot gnu.org
2024-01-29 16:46 ` pinskia at gcc dot gnu.org
2024-01-29 16:52 ` bugdal at aerifal dot cx
2024-01-29 16:55 ` pinskia at gcc dot gnu.org
2024-01-29 17:12 ` bugdal at aerifal dot cx

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).