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

            Bug ID: 86607
           Summary: constexpr function does not treat function pointers
                    with external linkage as constexpr
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tadeus.prastowo at unitn dot it
  Target Milestone: ---

Using http://godbolt.org, I see that the following program compiles in
any clang version that supports `-std=c++14' switch (>= 3.5) but fails
in any GCC version >= 5.1 while compiles in any GCC version <= 4.9.4
that supports `-std=c++14' switch (>= 4.8.5):

template<typename T, T v>
struct carrier {
  static constexpr T value = v;
};

template<typename T>
inline constexpr bool nontype_nontemplate_args_eq(T arg1, T arg2) {
  return arg1 == arg2;
}
template<typename T1, typename T2>
inline constexpr bool nontype_nontemplate_args_eq(T1, T2) {
  return false;
}

int fn1() {
  return 2;
}

int fn2() {
  return 17;
}

int main() {
  return carrier<bool, nontype_nontemplate_args_eq(&fn1, &fn2)>::value;
}

Any GCC version >= 5.1 should compile the program because `&fn1' and `&fn2' as
the arguments of constexpr function `nontype_nontemplate_args_eq' are constexpr
according to the C++ standard http://eel.is/c++draft/expr.const#6.2.

Reply via email to