https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69681
Bug ID: 69681 Summary: C/C++ FEs do not consider comparisons of distinct function pointers to be constant expressions Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ppalka at gcc dot gnu.org Target Milestone: --- The following test case fails to compile with both the C and C++ FEs: void foo () { } void bar () { } int x[(int)(&foo != &bar)]; The comparison "&foo != &bar" ought to be folded to 1 since both foo and bar distinct, defined functions at the point when the comparison is made. It is less obvious whether the comparison should be folded if foo and bar are not yet defined: void foo (); void bar (); int x[(int)(&foo != &bar)]; Because at this point one can add another declaration of foo and bar that give them the "weak" attribute, which would allow for &foo and &bar to be NULL pointers, thus actually making the result of the comparison indeterminate at compile time. If such code is allowed, the subsequent declarations of foo and bar must not declare these functions as weak, alias, etc, like in PR c++/61825. This issue also shows up when comparing and pointers to C++ member functions, and in C++ constexpr contexts.