diff mbox series

C++ PATCH for c++/83937, wrong C++17 overload resolution with constructor and {}

Message ID CADzB+2kma4KBuNYieu-WPRmGsGcyxzHz52AYbSE2mXOwNFJ-jQ@mail.gmail.com
State New
Headers show
Series C++ PATCH for c++/83937, wrong C++17 overload resolution with constructor and {} | expand

Commit Message

Jason Merrill March 16, 2018, 2:30 p.m. UTC
With T({}), the {} specifically initializes the first constructor
parameter, rather than T directly.  This is different from T{}, so we
need to check CONSTRUCTOR_IS_DIRECT_INIT.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox series

Patch

commit 96fb2fc01280452682585dcc68038f54f416d034
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 16 09:00:37 2018 -0400

            PR c++/83937 - wrong C++17 handling of init-list ctor argument.
    
            * call.c (build_special_member_call): Don't convert an init-list
            argument directly to the class type.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 67438ff2e94..4bd3190b42e 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8829,7 +8829,12 @@  build_special_member_call (tree instance, tree name, vec<tree, va_gc> **args,
 	/* If we're using this to initialize a non-temporary object, don't
 	   require the destructor to be accessible.  */
 	sub_complain |= tf_no_cleanup;
-      if (!reference_related_p (class_type, TREE_TYPE (arg)))
+      if (BRACE_ENCLOSED_INITIALIZER_P (arg)
+	  && !CONSTRUCTOR_IS_DIRECT_INIT (arg))
+	/* An init-list arg needs to convert to the parm type (83937), so fall
+	   through to normal processing.  */
+	arg = error_mark_node;
+      else if (!reference_related_p (class_type, TREE_TYPE (arg)))
 	arg = perform_implicit_conversion_flags (class_type, arg,
 						 sub_complain,
 						 flags);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-ctor2.C b/gcc/testsuite/g++.dg/cpp0x/initlist-ctor2.C
new file mode 100644
index 00000000000..ebacec0cff5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-ctor2.C
@@ -0,0 +1,15 @@ 
+// PR c++/83937
+// { dg-do run { target c++11 } }
+
+struct S
+{
+  S(int v = 42) {
+    if (v != int{})
+      __builtin_abort();
+  }
+};
+
+int main()
+{
+  S( {} );
+}