[Bug c++/107378] `get_if` implementation "is not a constant expression"

johelegp at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Oct 24 18:59:06 GMT 2022


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

--- Comment #3 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
MSVC accepts https://godbolt.org/z/nheYz9aez.

```C++
static_assert([i = 0] { return &i != nullptr; }());
```

```
<source>: In lambda function:
<source>:1:35: warning: the address of 'i' will never be NULL [-Waddress]
    1 | static_assert([i = 0] { return &i != nullptr; }());
      |                                ~~~^~~~~~~~~~
<source>:1:21: note: 'i' declared here
    1 | static_assert([i = 0] { return &i != nullptr; }());
      |                     ^
<source>: At global scope:
<source>:1:48: error: non-constant condition for static assertion
    1 | static_assert([i = 0] { return &i != nullptr; }());
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
<source>:1:35: error: '((&<anonymous>.<lambda()>::__i) != 0)' is not a constant
expression
    1 | static_assert([i = 0] { return &i != nullptr; }());
      |                                ~~~^~~~~~~~~~
Compiler returned: 1
```


More information about the Gcc-bugs mailing list