public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "insertinterestingnamehere at gmail dot com" <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 16:51:08 +0000 [thread overview] Message-ID: <bug-96877-4-Ge2rJcJAyp@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 #6 from Ian Henriksen <insertinterestingnamehere at gmail dot com> --- Thanks, this makes sense. I originally got this idea from https://stackoverflow.com/a/27489923. The discussion there implied there was some kind of ambiguity in the standard and showed some examples where exception specification appeared to be carried through as a part of the type in order to satisfy the rules about assigning to function pointers with noexcept specifiers. After revisiting their examples I've found that there's actually inconsistency with how actual values are handled vs how values from std::declval are handled. For example, the following is accepted as valid C++11 by both gcc and clang: #include <type_traits> #include <utility> void (*function_ptr)(void *) noexcept = nullptr; using function_type = decltype(function_ptr); using function_type_2 = std::remove_reference<decltype(std::declval<void (*)(void*) noexcept>())>::type; function_type thing1; function_type_2 thing2; static_assert(noexcept(thing1(nullptr)), ""); static_assert(!noexcept(thing2(nullptr)), ""); static_assert(std::is_same<function_type, function_type_2>::value, ""); See https://godbolt.org/z/YbzGM3. It's not obvious to me what the correct behavior would be based off of the actual wording of the standard, but this is bizarre. This behavior is consistent across clang and the last 3 major gcc releases, but the implicit inclusion of the exception specification in the type does not seem like something that should be relied upon.
prev parent reply other threads:[~2020-09-02 16: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 2020-09-02 16:51 ` insertinterestingnamehere at gmail dot com [this message]
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-Ge2rJcJAyp@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).