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.

Reply via email to