public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96877] Erroneous warning when default initializing function pointer types defined using std::declval Date: Wed, 02 Sep 2020 08:51:01 +0000 [thread overview] Message-ID: <bug-96877-4-ixe6Ah0Ufi@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96877-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96877 --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Ian Henriksen from comment #3) > The goal of doing it that way was get the exception specification onto the > pointer type in C++11 and C++14. The intent was to get the equivalent of > > typedef void(*function_type)(void*) noexcept; > > but with standards earlier than C++17. But you can't do that. There is no difference between void(*)(void*) noexcept and void(*)(void*) in C++14, they're the same type. It doesn't matter whether you write the type out, or do remove_reference_t<decltype(std::declval<T>())>, the type is the same. Concretely, it doesn't work: #include <utility> using function_type = decltype(std::declval<void (*)(void*) noexcept>()); static_assert( noexcept(std::declval<function_type>()(nullptr)), "" ); The assertion fails before C++17, because the type does not have noexcept in it. (In reply to Ian Henriksen from comment #4) > It's worth noting that, with g++ > > using function_type = void (*)(void*) noexcept; > > actually works, You can write that declaration, but the noexcept still isn't part of the type: #include <utility> using function_type = void (*)(void*) noexcept; static_assert( noexcept(std::declval<function_type>()(nullptr)), "" ); If you need C++17 then use C++17.
next prev parent reply other threads:[~2020-09-02 8:51 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-01 2:07 [Bug c++/96877] New: " insertinterestingnamehere at gmail dot com 2020-09-01 15:29 ` [Bug c++/96877] " insertinterestingnamehere at gmail dot com 2020-09-01 17:37 ` redi at gcc dot gnu.org 2020-09-01 19:19 ` insertinterestingnamehere at gmail dot com 2020-09-01 19:25 ` insertinterestingnamehere at gmail dot com 2020-09-02 8:51 ` redi at gcc dot gnu.org [this message] 2020-09-02 16:51 ` insertinterestingnamehere at gmail 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-96877-4-ixe6Ah0Ufi@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).