public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "EricMCornelius at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-52892-4@http.gcc.gnu.org/bugzilla/> (raw) 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 <cstdio> constexpr std::size_t fibonacci(std::size_t val) { return (val <= 2) ? 1 : fibonacci(val - 1) + fibonacci(val - 2); } template <typename Function> struct Defer { constexpr Defer(const Function func_) : func(func_) { } const Function func; template <typename... Args> constexpr auto operator () (const Args&... args) -> decltype(func(args...)) { return func(args...); } }; template <typename Function> constexpr Defer<Function> make_deferred(const Function f) { return Defer<Function>(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<Function>::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"); }
next reply other threads:[~2012-04-06 18:58 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-04-06 18:58 EricMCornelius at gmail dot com [this message] 2012-04-07 13:16 ` [Bug c++/52892] " daniel.kruegler at googlemail dot com 2012-05-29 9:28 ` adrien at guinet dot me 2013-05-02 14:57 ` paolo.carlini at oracle dot com 2014-08-27 17:04 ` paolo at gcc dot gnu.org 2014-08-27 17:05 ` paolo.carlini at oracle dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-52892-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).