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
Related missed-optimization bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43565
Confirmed. Clang accepts the code.
The inline part of the template variable does not make a difference. Reduced testcase: template <int> char hh= 0; static_assert(&hh<0> != &hh<1>, "should not be equal");
*** Bug 94716 has been marked as a duplicate of this bug. ***
Dup of bug 85428. *** This bug has been marked as a duplicate of bug 85428 ***