[Bug c++/85428] New: constexpr pointer equality comparison not considered constant expression

stinkingmadgod at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Apr 17 08:53:00 GMT 2018


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

            Bug ID: 85428
           Summary: constexpr pointer equality comparison not considered
                    constant expression
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

The following should compile

template<typename T>
struct S
{
    inline static char c;
};

void foo()
{
    constexpr auto t1 = &S<int>::c;
    constexpr auto t2 = &S<char>::c;
    static_assert(t1 != t2);
}

But won't, with error: non-constant condition for static assertion.

[expr.eq] says the pointers is specified to be unequal, and [expr.const] says
this is a constant expression.

However this compiles

inline char c1, c2;

void bar()
{
    constexpr auto t1 = &c1;
    constexpr auto t2 = &c2;
    static_assert(t1 != t2);
}

Related is bug 70248 where the compiler accepts unspecified equality
comparisons as constant expressions when it shouldn't.


More information about the Gcc-bugs mailing list