From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3378 invoked by alias); 6 Apr 2012 18:58:48 -0000 Received: (qmail 3366 invoked by uid 22791); 6 Apr 2012 18:58:47 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 Apr 2012 18:58:34 +0000 From: "EricMCornelius at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52892] New: Function pointer loses constexpr qualification Date: Fri, 06 Apr 2012 18:58:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: EricMCornelius at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg00444.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892 Bug #: 52892 Summary: Function pointer loses constexpr qualification Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: EricMCornelius@gmail.com The following test case is failing: #include constexpr std::size_t fibonacci(std::size_t val) { return (val <= 2) ? 1 : fibonacci(val - 1) + fibonacci(val - 2); } template struct Defer { constexpr Defer(const Function func_) : func(func_) { } const Function func; template constexpr auto operator () (const Args&... args) -> decltype(func(args...)) { return func(args...); } }; template constexpr Defer make_deferred(const Function f) { return Defer(f); } int main(int argc, char* argv[]) { constexpr auto deferred = make_deferred(&fibonacci); static_assert(deferred(25) == 75025, "Static fibonacci call failed"); } src/main.cpp: In function 'int main(int, char**)': src/main.cpp:151:3: error: non-constant condition for static assertion src/main.cpp:151:28: in constexpr expansion of 'deferred.Defer::operator()<{int}>((* &25))' src/main.cpp:140:24: error: expression 'fibonacci' does not designate a constexpr function test.make:129: recipe for target `obj/Debug/main.o' failed make[1]: *** [obj/Debug/main.o] Error 1 makefile:16: recipe for target `test' failed make: *** [test] Error 2 Based on my reading of the standard, this should be allowed behavior, and works as expected with clang 3.1 (152539). Note that the following behavior also fails similarly: int main(int argc, char* argv[]) { constexpr auto deferred = make_deferred(&fibonacci); constexpr auto func = deferred.func; constexpr auto val = func(25); } src/main.cpp: In function 'int main(int, char**)': src/main.cpp:152:31: error: expression 'fibonacci' does not designate a constexpr function Whereas this succeeds: int main(int argc, char* argv[]) { constexpr auto func = &fibonacci; static_assert(func(25) == 75025, "Static fibonacci call failed"); }