c++: vector of class with bool ctor [PR108195]
authorJason Merrill <jason@redhat.com>
Mon, 23 Jan 2023 20:03:47 +0000 (15:03 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 23 Jan 2023 21:12:52 +0000 (16:12 -0500)
The transformation done by r13-4564 to use the iterator constructor instead
of the initializer-list constructor breaks if the iterator pointers are
themselves treated as elements of an initializer-list, so check for that.

PR c++/108195

gcc/cp/ChangeLog:

* call.cc (build_user_type_conversion_1): Check whether the
iterators also find a list ctor.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-vect2.C: New test.

gcc/cp/call.cc
gcc/testsuite/g++.dg/cpp0x/initlist-vect2.C [new file with mode: 0644]

index a7de0e8..5715a7c 100644 (file)
@@ -4581,7 +4581,7 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags,
   if (tree iters = maybe_init_list_as_range (cand->fn, expr))
     if (z_candidate *cand2
        = build_user_type_conversion_1 (totype, iters, flags, tf_none))
-      if (cand2->viable == 1)
+      if (cand2->viable == 1 && !is_list_ctor (cand2->fn))
        {
          cand = cand2;
          expr = iters;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-vect2.C b/gcc/testsuite/g++.dg/cpp0x/initlist-vect2.C
new file mode 100644 (file)
index 0000000..eec7d34
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/108195
+// { dg-do run { target c++11 } }
+
+#include <vector>
+
+struct S
+{
+  S(bool) {}
+};
+
+int main()
+{
+  std::vector<S> v = { true, false, true };
+  if (v.size() != 3)
+    __builtin_abort ();
+}