https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116167

            Bug ID: 116167
           Summary: "static_cast" of member function pointer
                    (non-noexcept) to noexcept erroneously succeeds if not
                    overloaded
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: admin at hexadigm dot com
  Target Milestone: ---

The following code correctly fails to compile based on my research (though I
can't find the passage in the standard itself so still unconfirmed), but
successfully compiles when the "Whatever" overload taking a double is commented
out (so "Whatever" is no longer overloaded). I believe it should (likely) still
fail whether overloaded or not. It does so in Clang and MSVC though in Clang
(didn't check MSVC) the error is slightly different when it's not overloaded vs
when it is but it still "correctly" fails nevertheless. Tested the scenario in
C++17, C++20 and C++23.

The issue is that the "static_cast" from a non-noexcept function to one that is
"noexcept" is illegal to the best of my knowledge (?) so it should always fail
AFAIK (the issue is a bit fuzzy however but it would be surprising if the
standard supports two different behaviors for this scenario based on whether
the "static_cast" is targeting an overloaded function or not).

class Test
{
public:
    void Whatever(float)
    {
    }

    void Whatever(double)
    {
    }
};

int main()
{
    constexpr auto pWhatever = static_cast<void (Test::*)(float)
noexcept>(&Test::Whatever);

    return 0;
}

Reply via email to