[libcxx-commits] [PATCH] D147560: [libc++] Fix std::optional-related type deduction

Ian McKellar via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 4 17:30:36 PDT 2023


ianloic updated this revision to Diff 510975.
ianloic marked an inline comment as done.
ianloic added a comment.

A different approach


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147560

Files:
  libcxx/include/optional
  libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ambigous_constructor.pass.cpp


Index: libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ambigous_constructor.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ambigous_constructor.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+// <optional>
+
+#include <optional>
+
+#include "test_macros.h"
+
+struct Bar {
+  int s;
+};
+
+struct Foo {
+  Foo(Bar) {}
+  Foo(std::optional<int>) {}
+};
+
+int main(int, char**) {
+  Foo foo{{.s = 42}};
+
+  return 0;
+}
Index: libcxx/include/optional
===================================================================
--- libcxx/include/optional
+++ libcxx/include/optional
@@ -662,16 +662,16 @@
 
     // LWG2756: conditionally explicit conversion from _Up
     struct _CheckOptionalArgsConstructor {
-      template <class _Up>
+      template <class _Up, class _UpRR = add_rvalue_reference_t<_Up>>
       static constexpr bool __enable_implicit() {
-          return is_constructible_v<_Tp, _Up&&> &&
-                 is_convertible_v<_Up&&, _Tp>;
+          return is_constructible_v<_Tp, _UpRR> &&
+                 is_convertible_v<_UpRR, _Tp>;
       }
 
-      template <class _Up>
+      template <class _Up, class _UpRR = add_rvalue_reference_t<_Up>>
       static constexpr bool __enable_explicit() {
-          return is_constructible_v<_Tp, _Up&&> &&
-                 !is_convertible_v<_Up&&, _Tp>;
+          return is_constructible_v<_Tp, _UpRR> &&
+                 !is_convertible_v<_UpRR, _Tp>;
       }
     };
     template <class _Up>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147560.510975.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230405/25200a05/attachment.bin>


More information about the libcxx-commits mailing list