Bug 109518 - invalid constexpr code is accepted
Summary: invalid constexpr code is accepted
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2023-04-15 04:28 UTC by Darrell Wright
Modified: 2023-08-03 17:59 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-04-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Darrell Wright 2023-04-15 04:28:52 UTC
The following invalid code is UB but accepted by gcc.  The life of x has not started yet, https://eel.is/c++draft/basic.life#1.2 , but it is accessed.

constexpr void init(int & x) { x = 42; }

constexpr int foo() {
    int x = (init(x), x);
    return x;
}

static_assert( foo( ) == 42 );

https://gcc.godbolt.org/z/oGE51eMz4