https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70196
Bug ID: 70196
Summary: inconsistent constness of inequality of weak symbol
addresses
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
While testing a patch for bug 67376 I discovered that GCC treats certain
relational expressions involving addresses of weak symbols as constant while
others as not constant. Specifically, (&weakref < 0) and (0 <= &weakref) are
treated a constant expressions, while no other relational or inequality
expressions are. It seems that they should all be treated consistently (as
done by Clang), otherwise users are bound to get confused about what's valid
and why.
$ cat v.c && /home/msebor/build/gcc-trunk-svn/gcc/xgcc
-B/home/msebor/build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -o/dev/null
-xc++ v.c
extern __attribute__ ((weak)) int i;
constexpr int *p = 0;
constexpr int *q = &i;
static_assert (p == q, "p == q");
static_assert (!(q < p), "!(a < p)"); // accepted and true
static_assert (p <= q, "p <= q"); // accepted and true
v.c:6:1: error: non-constant condition for static assertion
static_assert (p == q, "p == q");
^~~~~~~~~~~~~
v.c:6:18: error: ‘((& i) == 0u)’ is not a constant expression
static_assert (p == q, "p == q");
~~^~~~