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

            Bug ID: 88840
           Summary: [9 Regression] std::allocator::construct signature
                    might be ill-formed now
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

#include <memory>

struct X {
  X(int);
};

constexpr bool nothrow =
noexcept(std::allocator<X>().construct(std::declval<X*>()));

That construct() call would ill-formed, because the type isn't default
constructible, but until recently it was possible to query whether it could
throw or not. With current trunk the declaration includes an
exception-specification, which makes it ill-formed:

In file included from
/home/jwakely/gcc/9/include/c++/9.0.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
                 from
/home/jwakely/gcc/9/include/c++/9.0.0/bits/allocator.h:46,
                 from /home/jwakely/gcc/9/include/c++/9.0.0/memory:63,
                 from construct.cc:1:
/home/jwakely/gcc/9/include/c++/9.0.0/ext/new_allocator.h: In instantiation of
'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up =
X; _Args = {}; _Tp = X]':
construct.cc:7:83:   required from here
/home/jwakely/gcc/9/include/c++/9.0.0/ext/new_allocator.h:145:20: error: no
matching function for call to 'X::X()'
  145 |  noexcept(noexcept(::new((void *)__p)
      |                    ^~~~~~~~~~~~~~~~~~
  146 |        _Up(std::forward<_Args>(__args)...)))
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
construct.cc:4:3: note: candidate: 'X::X(int)'
    4 |   X(int);
      |   ^
construct.cc:4:3: note:   candidate expects 1 argument, 0 provided
construct.cc:3:8: note: candidate: 'constexpr X::X(const X&)'
    3 | struct X {
      |        ^
construct.cc:3:8: note:   candidate expects 1 argument, 0 provided
construct.cc:3:8: note: candidate: 'constexpr X::X(X&&)'
construct.cc:3:8: note:   candidate expects 1 argument, 0 provided


We could constrain the declaration with SFINAE, but the program would still be
ill-formed (you still can't ask if the construct() call would throw, because
the declaration would be SFINAE'd out).

Reply via email to