This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52892] Function pointer loses constexpr qualification
- From: "adrien at guinet dot me" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 29 May 2012 09:26:29 +0000
- Subject: [Bug c++/52892] Function pointer loses constexpr qualification
- Auto-submitted: auto-generated
- References: <bug-52892-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892
Adrien Guinet <adrien at guinet dot me> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |adrien at guinet dot me
--- Comment #2 from Adrien Guinet <adrien at guinet dot me> 2012-05-29 09:26:29 UTC ---
Hello everyone,
Im ay have an issue related to this issue, if that can help:
#include <iostream>
struct A
{
void f(int i) { std::cout << "f " << i << " " << _i << std::endl; }
void f2(int i) { std::cout << "f2 " << i << " " << _i << std::endl; }
int _i;
};
template <typename F, F f>
struct class_f
{
typedef F f_type;
static constexpr f_type f_value = f;
static constexpr f_type get() { return f; }
};
int main()
{
typedef class_f<decltype(&A::f), &A::f> ff_t;
// This does not compile
class_f<ff_t::f_type, ff_t::f_value> ff;
// This does not compile either
class_f<ff_t::f_type, static_cast<ff_t::f_type>(&A::f)> ff2;
// This does
class_f<ff_t::f_type, &A::f> ff_works;
}
It looks like using a function pointer that has been "instantiated" as an
"f_type" makes the compilation fails. here is the output of g++-4.7 with the
first "failing" tests :
$ g++-4.7 -std=c++0x ftempl.cpp
ftempl.cpp: In function âint main()â:
ftempl.cpp:24:37: error: could not convert template argument âclass_f<void
(A::*)(int), &A::f>::f_valueâ to âvoid (A::*)(int)â
ftempl.cpp:24:41: error: invalid type in declaration before â;â token
$ g++-4.7 --version
g++-4.7 (Debian 4.7.0-8) 4.7.0