[libcxx-commits] [PATCH] D110347: [libc++] Do not enable P1951 before C++23, since it's a breaking change

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 23 10:20:01 PDT 2021


Quuxplusone requested changes to this revision.
Quuxplusone added inline comments.
This revision now requires changes to proceed.


================
Comment at: libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.brace-init.P1951.pass.cpp:20-28
+    // Example 1:
+    // Without P1951, we call the `pair(const string&, const vector<int>&)` constructor (the converting constructor is
+    // not usable because we can't deduce from an initializer list), which creates the string temporary as part of the
+    // call to f. With P1951, we call the `pair(U&&, V&&)` constructor, which creates a string temporary inside the
+    // pair constructor, and that temporary doesn't live long enough any more.
+    {
+        auto f = [](std::pair<const std::string&, std::vector<int>>) { };
----------------
Well, this //compiles// either way, right? So to actually //test// the situation, it would be better to actually use the string's contents inside `f`. Or write a contrived toy version like
```
struct A {
    int *p_;
    A(int *p) : p_(p) { *p_ += 1; }
    A(const A& a) : p_(a.p_) { *p_ += 1; }
    ~A() { *p_ -= 1; }
};
int i = 0;
auto f = [&](std::pair<int, const A&>) { assert(i >= 1); };
f({42, &i});
```
https://godbolt.org/z/39q13bx41
Looks like libstdc++ did it as a DR (or has some other bug), and MSVC hasn't implemented it at all yet?


================
Comment at: libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.brace-init.P1951.pass.cpp:34-37
+    {
+        const int n = 5;
+        (void) []{ std::pair<int, long>({1}, n); };
+    }
----------------
This test seems fine, since the symptom is "fail to compile."
Weirdly, libstdc++ is OK with this test; which is why I wondered above if they had some other bug causing the first test to fail.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110347/new/

https://reviews.llvm.org/D110347



More information about the libcxx-commits mailing list