public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator
@ 2021-06-15 19:58 rkhlebnikov at bloomberg dot net
  2021-06-16  9:13 ` [Bug c++/101087] [9/10/11/12 Regression] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: rkhlebnikov at bloomberg dot net @ 2021-06-15 19:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101087
           Summary: Unevaluated operand of sizeof affects noexcept
                    operator
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rkhlebnikov at bloomberg dot net
  Target Milestone: ---

clang, icc, MSVC all agree that the following `static_assert` should pass:

```
int f();
static_assert(noexcept(sizeof(f())), "");  // Fails on GCC
```

Such is not the case for gcc.

However, adding `decltype` to the mix helps:

```
int f();
static_assert(noexcept(sizeof(decltype(f()))), "");  // OK
```

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/101087] [9/10/11/12 Regression] Unevaluated operand of sizeof affects noexcept operator
  2021-06-15 19:58 [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator rkhlebnikov at bloomberg dot net
@ 2021-06-16  9:13 ` redi at gcc dot gnu.org
  2021-07-08  0:21 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-16  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Target Milestone|---                         |9.5
   Last reconfirmed|                            |2021-06-16
            Summary|Unevaluated operand of      |[9/10/11/12 Regression]
                   |sizeof affects noexcept     |Unevaluated operand of
                   |operator                    |sizeof affects noexcept
                   |                            |operator
      Known to fail|                            |10.3.0, 11.1.0, 12.0,
                   |                            |4.8.0, 9.4.0
      Known to work|                            |4.7.4
                 CC|                            |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It compiled with GCC 4.7 but stopped with r192141 (or r192142 but almost
certainly the former):

    cp-tree.h (SIZEOF_EXPR_TYPE_P): Define.

    cp/
            * cp-tree.h (SIZEOF_EXPR_TYPE_P): Define.
            * tree.c (cp_tree_equal): Handle SIZEOF_EXPR with
            SIZEOF_EXPR_TYPE_P.
            * mangle.c (write_expression): Likewise.
            * cxx-pretty-print.c (pp_cxx_unary_expression): Likewise.
            * error.c (dump_expr): Likewise.
            * parser.c (cp_parser_unary_expression): For sizeof call
            cxx_sizeof_or_alignof_{type,expr} just for diagnostics and
            return SIZEOF_EXPR with the operand.
            * pt.c (tsubst_copy, tsubst_copy_and_build): For SIZEOF_EXPR,
            call cxx_sizeof_or_alignof_{type,expr} for diagnostics, but
            return SIZEOF_EXPR with tsubsted operand.
            (value_dependent_expression_p): Handle SIZEOF_EXPR with
            SIZEOF_EXPR_TYPE_P.
            (instantiation_dependent_r): Likewise.
            * call.c (null_ptr_cst_p): Call maybe_constant_value for C++98.
            * semantics.c (finish_call_expr): Call
            sizeof_pointer_memaccess_warning if needed.
            (cxx_eval_constant_expression): Handle SIZEOF_EXPR.
            (potential_constant_expression_1): Remove early exit for
            C++98.  Handle PROPERTY_REF.
            * decl.c (duplicate_decls): When redeclaring a builtin function,
            keep the merged decl builtin also if newdecl is a gnu_inline
            inline definition.
            (fold_sizeof_expr_r): New function.
            (compute_array_index_type): Fold SIZEOF_EXPRs in itype.
            * cp-gimplify.c (cp_genericize_r): Fold SIZEOF_EXPR.
            * typeck.c (cp_build_binary_op): For warn_for_sign_compare
            try harder using maybe_constant_value to get INTEGER_CSTs.

            * decl.c (stabilize_vla_size): Call pointer_set_destroy
            at the end.
    testsuite/
            * g++.dg/torture/Wsizeof-pointer-memaccess1.C: New test.
            * g++.dg/torture/Wsizeof-pointer-memaccess2.C: New test.
            * g++.dg/warn/Wsign-compare-5.C: New test.
            * g++.dg/warn/Wsizeof-pointer-memaccess-1.C: New test.
            * g++.dg/warn/Wnull-conversion-1.C: For c++11 add dg-error.
            * g++.dg/ext/builtin30.C: New test.
            * g++.dg/ext/vla12.C: New test.
            * gcc.dg/builtins-85.c: New test.
    libstdc++-v3/
            * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust line
            numbers.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/101087] [9/10/11/12 Regression] Unevaluated operand of sizeof affects noexcept operator
  2021-06-15 19:58 [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator rkhlebnikov at bloomberg dot net
  2021-06-16  9:13 ` [Bug c++/101087] [9/10/11/12 Regression] " redi at gcc dot gnu.org
@ 2021-07-08  0:21 ` mpolacek at gcc dot gnu.org
  2021-07-08 21:39 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-08  0:21 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Testing a patch.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/101087] [9/10/11/12 Regression] Unevaluated operand of sizeof affects noexcept operator
  2021-06-15 19:58 [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator rkhlebnikov at bloomberg dot net
  2021-06-16  9:13 ` [Bug c++/101087] [9/10/11/12 Regression] " redi at gcc dot gnu.org
  2021-07-08  0:21 ` mpolacek at gcc dot gnu.org
@ 2021-07-08 21:39 ` cvs-commit at gcc dot gnu.org
  2021-07-08 21:48 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-08 21:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:dee00bf6894be0cabb8f263c993357a6f8444f8b

commit r12-2174-gdee00bf6894be0cabb8f263c993357a6f8444f8b
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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/101087] [9/10/11/12 Regression] Unevaluated operand of sizeof affects noexcept operator
  2021-06-15 19:58 [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator rkhlebnikov at bloomberg dot net
                   ` (2 preceding siblings ...)
  2021-07-08 21:39 ` cvs-commit at gcc dot gnu.org
@ 2021-07-08 21:48 ` cvs-commit at gcc dot gnu.org
  2021-07-08 22:04 ` cvs-commit at gcc dot gnu.org
  2021-07-08 22:06 ` [Bug c++/101087] [9 " mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-08 21:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:cbef732522568f8adce46c472b16391c864d0fd0

commit r11-8709-gcbef732522568f8adce46c472b16391c864d0fd0
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 dee00bf6894be0cabb8f263c993357a6f8444f8b)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/101087] [9/10/11/12 Regression] Unevaluated operand of sizeof affects noexcept operator
  2021-06-15 19:58 [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator rkhlebnikov at bloomberg dot net
                   ` (3 preceding siblings ...)
  2021-07-08 21:48 ` cvs-commit at gcc dot gnu.org
@ 2021-07-08 22:04 ` cvs-commit at gcc dot gnu.org
  2021-07-08 22:06 ` [Bug c++/101087] [9 " mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-08 22:04 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/101087] [9 Regression] Unevaluated operand of sizeof affects noexcept operator
  2021-06-15 19:58 [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator rkhlebnikov at bloomberg dot net
                   ` (4 preceding siblings ...)
  2021-07-08 22:04 ` cvs-commit at gcc dot gnu.org
@ 2021-07-08 22:06 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-08 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
            Summary|[9/10/11/12 Regression]     |[9 Regression] Unevaluated
                   |Unevaluated operand of      |operand of sizeof affects
                   |sizeof affects noexcept     |noexcept operator
                   |operator                    |
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 10+.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-07-08 22:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 19:58 [Bug c++/101087] New: Unevaluated operand of sizeof affects noexcept operator rkhlebnikov at bloomberg dot net
2021-06-16  9:13 ` [Bug c++/101087] [9/10/11/12 Regression] " redi at gcc dot gnu.org
2021-07-08  0:21 ` mpolacek at gcc dot gnu.org
2021-07-08 21:39 ` cvs-commit at gcc dot gnu.org
2021-07-08 21:48 ` cvs-commit at gcc dot gnu.org
2021-07-08 22:04 ` cvs-commit at gcc dot gnu.org
2021-07-08 22:06 ` [Bug c++/101087] [9 " mpolacek at gcc dot gnu.org

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).