Bug 86607 - constexpr function does not treat function pointers with external linkage as constexpr
Summary: constexpr function does not treat function pointers with external linkage as ...
Status: RESOLVED DUPLICATE of bug 77911
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2018-07-20 11:23 UTC by Tadeus Prastowo
Modified: 2021-08-05 02:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-07-30 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tadeus Prastowo 2018-07-20 11:23:47 UTC
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.
Comment 1 Drea Pinski 2021-08-05 02:32:56 UTC
This is a dup of bug 77911.

*** This bug has been marked as a duplicate of bug 77911 ***