[libcxx-commits] [PATCH] D69603: [libcxx] Add deduction guides for shared_ptr and weak_ptr

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 31 23:34:41 PDT 2019


mclow.lists added a comment.

The tests should be more comprehensive; they should `ASSERT_SAME_TYPE(decltype(s), XXX)` to make sure that the deduction guides actually return the correct type, rather than just compile.



================
Comment at: libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp:24
+{
+  {
+    auto s0 = std::shared_ptr<A>(new A);
----------------
When you're testing type-deduction, I find it much easier to convince myself that the types are correct if you are explicit whenever possible (instead of just `auto` everywhere)
Example:
```
    using SP = std::shared_ptr<A>;
    using WP = std::weak_ptr<A>;

    SP s0 = new A;
    WP w = s0;
    auto s = std::shared_ptr(w);
    ASSERT_SAME_TYPE(decltype(s), SP);
```

Also, you should check the value of `s`.   Make sure it points to the same thing as `s0`.



Repository:
  rCXX libc++

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

https://reviews.llvm.org/D69603





More information about the libcxx-commits mailing list