Bug 102603 - Compile-time evaluation of indirection via dangling pointer is not rejected
Summary: Compile-time evaluation of indirection via dangling pointer is not rejected
Status: RESOLVED DUPLICATE of bug 70331
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2021-10-05 08:19 UTC by Fedor Chelnokov
Modified: 2021-10-05 14:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fedor Chelnokov 2021-10-05 08:19:18 UTC
The program as follows is ill-formed:
```
constexpr bool g() {
    int * p = nullptr;
    {
        int c = 0;
        p = &c;
    }
    return *p == 0; //indirection via dangling pointer
};

int main() {
    static_assert( g() );
}
```
but GCC erroneously accepts it, demo: https://gcc.godbolt.org/z/8xE7csGKo

The compiler must fail the program, see stackoverflow explanation: https://stackoverflow.com/a/69446660/7325599
Comment 1 Drea Pinski 2021-10-05 14:15:11 UTC
Dup of bug 70331.

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