[Bug c++/91693] New: Comparing addresses of templated inline vars gets bogus "not a constant expression" error
jorg.brown at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Sep 6 20:58:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91693
Bug ID: 91693
Summary: Comparing addresses of templated inline vars gets
bogus "not a constant expression" error
Product: gcc
Version: 9.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jorg.brown at gmail dot com
Target Milestone: ---
This code works just fine:
inline int inline1 = 0;
inline int inline2 = 0;
static_assert(&inline1 == &inline1);
static_assert(&inline1 != &inline2);
But this code doesn't:
template<typename T>
inline int NullT = 0;
struct A1;
struct A2;
static_assert(&NullT<A1> == &NullT<A1>);
static_assert(&NullT<A1> != &NullT<A2>);
Specifically, it produces this incorrect error:
<source>:13:26: error: non-constant condition for static assertion
13 | static_assert(&NullT<A1> != &NullT<A2>);
| ~~~~~~~~~~~^~~~~~~~~~~~~
<source>:13:26: error: '((& NullT<A1>) != (& NullT<A2>))' is not a constant
expression
= = =
Problem reproduces in gcc 7.1 through 9.2; this code works in clang (tested as
far back as 5.0) as well as MSVC (tested as far back as v19.14)
See https://godbolt.org/z/njyH5d
More information about the Gcc-bugs
mailing list