]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add workaround for std::make_integer_sequence bug [PR111357]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 14 Sep 2023 08:18:34 +0000 (09:18 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 14 Sep 2023 13:41:34 +0000 (14:41 +0100)
The compiler bug has been fixed on trunk, but we need this workaround on
the branches.

libstdc++-v3/ChangeLog:

PR c++/111357
* include/std/utility (make_integer_sequence): Add cast.
* testsuite/20_util/integer_sequence/pr111357.cc: New test.

(cherry picked from commit 7b0abd4a8ee9d2057febe443de67009dcdfe7574)

libstdc++-v3/include/std/utility
libstdc++-v3/testsuite/20_util/integer_sequence/pr111357.cc [new file with mode: 0644]

index f54f75b4d3883e56ea1fb8e78c878e640efde8bb..7ebb8a552c14c45cf2454113c864491f5dae1442 100644 (file)
@@ -331,7 +331,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __has_builtin(__make_integer_seq)
       = __make_integer_seq<integer_sequence, _Tp, _Num>;
 #else
-      = integer_sequence<_Tp, __integer_pack(_Num)...>;
+      = integer_sequence<_Tp, __integer_pack(_Tp(_Num))...>;
 #endif
 
   /// Alias template index_sequence
diff --git a/libstdc++-v3/testsuite/20_util/integer_sequence/pr111357.cc b/libstdc++-v3/testsuite/20_util/integer_sequence/pr111357.cc
new file mode 100644 (file)
index 0000000..1ad06b7
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-do compile { target c++14 } }
+
+// PR c++/111357 - __integer_pack fails to work with values of dependent type
+// convertible to integers in noexcept context
+
+#include <utility>
+
+using std::integer_sequence;
+using std::make_integer_sequence;
+
+template<int... V>
+void g(integer_sequence<int,V...>)
+{}
+
+template<typename ...T>
+struct c1
+{
+  static constexpr int value = 1;
+  constexpr operator int() { return value; }
+};
+
+template<typename T>
+struct R
+{
+  using S = make_integer_sequence<int,c1<T>{}>;
+
+  R() noexcept(noexcept(g(S()))) // { dg-bogus "argument to .__integer_pack." }
+  {}
+};
+
+int main()
+{
+  R<int>();
+}