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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Here's a C++17 test that doesn't rely on parenthesized init of aggregates:

#include <vector>
#include <memory_resource>

void test1()
{
#if __cplusplus >= 202002L
  struct S { int i; };
  static_assert(std::is_constructible_v<S, int&>);

  std::vector<int> base_v;
  std::vector<S> v;
  v.insert(v.end(), base_v.begin(), base_v.end());
#endif
}

void test2()
{
  struct S { explicit S(int) { } };
  static_assert(std::is_constructible_v<S, int&>);

  std::vector<int> base_v;
  std::vector<S> v;
  v.insert(v.end(), base_v.begin(), base_v.end());
}

void test3()
{
  struct S {
    S(int) { }
    void operator=(int) = delete;
  };
  static_assert(std::is_constructible_v<S, int&>);

  std::vector<int> base_v;
  std::vector<S> v;
  v.insert(v.end(), base_v.begin(), base_v.end());
}

void test4()
{
  struct S {
    using allocator_type = std::pmr::polymorphic_allocator<S>;
    S() { }
    S(allocator_type) { }
    S(int) { throw; }
    S(int, allocator_type) { }
    S(const S&, allocator_type) { }
  };
  static_assert(std::is_constructible_v<S, int&>);

  std::vector<int> base_v(1);
  std::pmr::vector<S> v(1);
  v.reserve(2);
  v.insert(v.begin(), base_v.begin(), base_v.end());
}

int main()
{
  test1();
  test2();
  test3();
  test4();
}

test1 is ill-formed in C++20 (and a no-op in C++17), test2, and test3 are
ill-formed in all cases, and test4 fails at runtime.

They should all compile and run successfully.

Reply via email to