public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
@ 2021-05-07 11:16 oleksandr.koval.dev at gmail dot com
  2021-09-06 15:54 ` [Bug c++/100470] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: oleksandr.koval.dev at gmail dot com @ 2021-05-07 11:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100470
           Summary: std::is_nothrow_move_constructible incorrect behavior
                    for explicitly defaulted members
           Product: gcc
           Version: 11.1.0
               URL: https://godbolt.org/z/hqeh4E3M8
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: oleksandr.koval.dev at gmail dot com
  Target Milestone: ---

Explicit exception specification should be the actual one, hence, S2 should NOT
be nothrow-constructible.

#include <type_traits>

struct S1{
    S1(S1&&) noexcept(false);
};
struct S2{
    S2(S2&&) noexcept(false) = default;
};
struct S3{
    S3(S3&&) noexcept(false){}
};
struct S4{
    S4(S4&&) = default;
};

static_assert(!std::is_nothrow_move_constructible_v<S1>);  // OK
static_assert(!std::is_nothrow_move_constructible_v<S2>);  // failed
static_assert(!std::is_nothrow_move_constructible_v<S3>);  // OK
static_assert(std::is_nothrow_move_constructible_v<S4>);   // OK

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

* [Bug c++/100470] std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
  2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
@ 2021-09-06 15:54 ` redi at gcc dot gnu.org
  2022-09-20  9:23 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-06 15:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |c++

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a compiler bug, the library trait just asks the compiler.

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

* [Bug c++/100470] std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
  2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
  2021-09-06 15:54 ` [Bug c++/100470] " redi at gcc dot gnu.org
@ 2022-09-20  9:23 ` redi at gcc dot gnu.org
  2022-09-20  9:43 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-20  9:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fchelnokov at gmail dot com

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 106968 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100470] std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
  2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
  2021-09-06 15:54 ` [Bug c++/100470] " redi at gcc dot gnu.org
  2022-09-20  9:23 ` redi at gcc dot gnu.org
@ 2022-09-20  9:43 ` redi at gcc dot gnu.org
  2022-09-20  9:50 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-20  9:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |wrong-code
   Last reconfirmed|                            |2022-09-20

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1286r2.html says that
S" has a potentially-throwing move constructor.

It looks like the __is_nothrow_constructible built-in gets this wrong:

using size_t = decltype(sizeof(0));
void* operator new(size_t, void* p) noexcept { return p; }

namespace std {
template<typename T> T&& declval() noexcept;

template<typename T>
constexpr bool is_nothrow_move_constructible_v
  = noexcept(new (declval<void*>()) T(declval<T>()));
}

struct S1{
    S1(S1&&) noexcept(false);
};
struct S2{
    S2(S2&&) noexcept(false) = default;
};
struct S3{
    S3(S3&&) noexcept(false){}
};
struct S4{
    S4(S4&&) = default;
};

static_assert(!std::is_nothrow_move_constructible_v<S1>);  // OK
static_assert(!std::is_nothrow_move_constructible_v<S2>);  // OK
static_assert(!std::is_nothrow_move_constructible_v<S3>);  // OK
static_assert( std::is_nothrow_move_constructible_v<S4>);  // OK

static_assert(!__is_nothrow_constructible(S1, S1));  // OK
static_assert(!__is_nothrow_constructible(S2, S2));  // failed
static_assert(!__is_nothrow_constructible(S3, S3));  // OK
static_assert( __is_nothrow_constructible(S4, S4));  // OK

This makes it a libstdc++ regression in GCC 11.1 and later, because we use
__is_nothrow_construcitble now, instead of a pure library implementation for
the traits.

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

* [Bug c++/100470] std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
  2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
                   ` (2 preceding siblings ...)
  2022-09-20  9:43 ` redi at gcc dot gnu.org
@ 2022-09-20  9:50 ` redi at gcc dot gnu.org
  2023-08-08 21:45 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-20  9:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
My guess is that either is_nothrow_xible or check_noexcept_r assumes that a
trivial special member is always non-throwing, but that fails to consider the
P1206 rule that says if there's an explicit noexcept-specifier, that overrides
the implicit one.

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

* [Bug c++/100470] std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
  2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
                   ` (3 preceding siblings ...)
  2022-09-20  9:50 ` redi at gcc dot gnu.org
@ 2023-08-08 21:45 ` pinskia at gcc dot gnu.org
  2023-10-26 16:07 ` johelegp at gmail dot com
  2023-12-11  2:34 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-08 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nikolasklauser at berlin dot de

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 106611 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100470] std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
  2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
                   ` (4 preceding siblings ...)
  2023-08-08 21:45 ` pinskia at gcc dot gnu.org
@ 2023-10-26 16:07 ` johelegp at gmail dot com
  2023-12-11  2:34 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: johelegp at gmail dot com @ 2023-10-26 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

Johel Ernesto Guerrero Peña <johelegp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johelegp at gmail dot com

--- Comment #6 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Is this a duplicate of Bug 96090?

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

* [Bug c++/100470] std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members
  2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
                   ` (5 preceding siblings ...)
  2023-10-26 16:07 ` johelegp at gmail dot com
@ 2023-12-11  2:34 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-11  2:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

https://gcc.gnu.org/g:4719b6f5ae4d758f193a17bbd5fb6cbacd702a23

commit r14-6395-g4719b6f5ae4d758f193a17bbd5fb6cbacd702a23
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Sat Oct 28 16:04:52 2023 +1100

    c++: Fix noexcept checking for trivial operations [PR96090]

    This patch stops eager folding of trivial operations (construction and
    assignment) from occurring when checking for noexceptness. This was
    previously done in PR c++/53025, but only for copy/move construction,
    and the __is_nothrow_xible builtins did not receive the same treatment
    when they were added.

    To handle `is_nothrow_default_constructible`, the patch also ensures
    that when no parameters are passed we do value initialisation instead of
    just building the constructor call: in particular, value-initialisation
    doesn't necessarily actually invoke the constructor for trivial default
    constructors, and so we need to handle this case as well.

    This is contrary to the proposed resolution of CWG2820; for now we just
    ensure it matches the behaviour of the `noexcept` operator and create
    testcases formalising this, and if that issue gets accepted we can
    revisit.

            PR c++/96090
            PR c++/100470

    gcc/cp/ChangeLog:

            * call.cc (build_over_call): Prevent folding of trivial special
            members when checking for noexcept.
            * method.cc (constructible_expr): Perform value-initialisation
            for empty parameter lists.
            (is_nothrow_xible): Treat as noexcept operator.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/noexcept81.C: New test.
            * g++.dg/ext/is_nothrow_constructible7.C: New test.
            * g++.dg/ext/is_nothrow_constructible8.C: New test.

    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>

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

end of thread, other threads:[~2023-12-11  2:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 11:16 [Bug libstdc++/100470] New: std::is_nothrow_move_constructible incorrect behavior for explicitly defaulted members oleksandr.koval.dev at gmail dot com
2021-09-06 15:54 ` [Bug c++/100470] " redi at gcc dot gnu.org
2022-09-20  9:23 ` redi at gcc dot gnu.org
2022-09-20  9:43 ` redi at gcc dot gnu.org
2022-09-20  9:50 ` redi at gcc dot gnu.org
2023-08-08 21:45 ` pinskia at gcc dot gnu.org
2023-10-26 16:07 ` johelegp at gmail dot com
2023-12-11  2:34 ` cvs-commit 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).