public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: vector of class with bool ctor [PR108195]
@ 2023-01-23 21:12 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-01-23 21:12 UTC (permalink / raw)
  To: gcc-patches

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

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                              |  2 +-
 gcc/testsuite/g++.dg/cpp0x/initlist-vect2.C | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-vect2.C

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index a7de0e8e9a6..5715a7cd1de 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -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
index 00000000000..eec7d340fd1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-vect2.C
@@ -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 ();
+}

base-commit: 4b125d01a5d5e601961419396332b74eea2219bb
-- 
2.31.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-23 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-23 21:12 [pushed] c++: vector of class with bool ctor [PR108195] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).