[Bug c++/101087] [9/10/11/12 Regression] Unevaluated operand of sizeof affects noexcept operator

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jul 8 22:04:49 GMT 2021


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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:879e7df182910886789aaac493efb0bc31ab0982

commit r10-9972-g879e7df182910886789aaac493efb0bc31ab0982
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Jul 7 20:02:18 2021 -0400

    c++: Fix noexcept with unevaluated operand [PR101087]

    It sounds plausible that this assert

      int f();
      static_assert(noexcept(sizeof(f())));

    should pass: sizeof produces a std::size_t and its operand is not
    evaluated, so it can't throw.  noexcept should only evaluate to
    false for potentially evaluated operands.  Therefore I think that
    check_noexcept_r shouldn't walk into operands of sizeof/decltype/
    alignof/typeof.

            PR c++/101087

    gcc/cp/ChangeLog:

            * cp-tree.h (unevaluated_p): New.
            * except.c (check_noexcept_r): Use it.  Don't walk into
            unevaluated operands.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/noexcept70.C: New test.

    (cherry picked from commit cbef732522568f8adce46c472b16391c864d0fd0)


More information about the Gcc-bugs mailing list