]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix constraint on std::basic_format_string [PR108024]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 12 Dec 2022 11:40:07 +0000 (11:40 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 12 Dec 2022 14:00:09 +0000 (14:00 +0000)
Also remove some redundant std::move calls for return statements.

libstdc++-v3/ChangeLog:

PR libstdc++/108024
* include/std/format (basic_format_string): Fix constraint.
* testsuite/std/format/format_string.cc: New test.

libstdc++-v3/include/std/format
libstdc++-v3/testsuite/std/format/format_string.cc [new file with mode: 0644]

index 269f8f6cc6a4c22adee339210227f7e2bca99474..9c928371415f01822287258caec36953e4e1401f 100644 (file)
@@ -110,7 +110,8 @@ namespace __format
   template<typename _CharT, typename... _Args>
     struct basic_format_string
     {
-      template<convertible_to<basic_string_view<_CharT>> _Tp>
+      template<typename _Tp>
+       requires convertible_to<const _Tp&, basic_string_view<_CharT>>
        consteval
        basic_format_string(const _Tp& __s);
 
@@ -609,7 +610,7 @@ namespace __format
       else
        for (_CharT __c : __str)
          *__out++ = __c;
-      return std::move(__out);
+      return __out;
     }
 
   // Write STR to OUT with NFILL copies of FILL_CHAR specified by ALIGN.
@@ -664,7 +665,7 @@ namespace __format
       __out = __format::__write(std::move(__out), __str);
       __pad(__r, __out);
 
-      return std::move(__out);
+      return __out;
     }
 
   // A lightweight optional<locale>.
@@ -3626,7 +3627,8 @@ namespace __format
 /// @endcond
 
   template<typename _CharT, typename... _Args>
-    template<convertible_to<basic_string_view<_CharT>> _Tp>
+    template<typename _Tp>
+      requires convertible_to<const _Tp&, basic_string_view<_CharT>>
       consteval
       basic_format_string<_CharT, _Args...>::
       basic_format_string(const _Tp& __s)
diff --git a/libstdc++-v3/testsuite/std/format/format_string.cc b/libstdc++-v3/testsuite/std/format/format_string.cc
new file mode 100644 (file)
index 0000000..1dd6ca8
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+#include <format>
+
+struct Str
+{
+  consteval operator std::string_view() const { return ""; }
+  operator std::string_view() = delete;
+};
+
+// PR libstdc++/108024
+static_assert( std::is_constructible_v<std::format_string<>, const Str&> );
+static_assert( std::is_convertible_v<const Str&, std::format_string<>> );
+
+constinit std::format_string<> s = Str();