public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch/RFC] PR 58753 & 58930
@ 2014-05-15 13:47 Paolo Carlini
  2014-05-15 20:25 ` Paolo Carlini
  2014-05-19 18:28 ` Jason Merrill
  0 siblings, 2 replies; 8+ messages in thread
From: Paolo Carlini @ 2014-05-15 13:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

Hi,

I'm trying to make progress on these two issues, which seem closely 
related to me. Both only happen for NSDMIs in template classes, thus 
when cp_parser_late_parse_one_default_arg sees processing_template_decl 
!= 0 and doesn't call digest_init_flags directly, thus produces a 
CONSTRUCTOR (vs, eg, a TARGET_EXPR). Then, I think that the problem - 
thus the incorrect diagnostic and the rejection - must be in 
perform_member_init, which doesn't early handle such CONSTRUCTOR with 
DIRECT_LIST_INIT_P true, thus doesn't call digest_init. The below passes 
testing and fixes all the snippets we have got for those two PRs.

Thanks!
Paolo.

////////////////////

[-- Attachment #2: patch_58753_58930 --]
[-- Type: text/plain, Size: 1654 bytes --]

Index: cp/init.c
===================================================================
--- cp/init.c	(revision 210459)
+++ cp/init.c	(working copy)
@@ -644,7 +644,9 @@ perform_member_init (tree member, tree init)
 		    || (TREE_CODE (init) == TREE_LIST
 			&& DIRECT_LIST_INIT_P (TREE_VALUE (init))))
 		   && (CP_AGGREGATE_TYPE_P (type)
-		       || is_std_init_list (type)))))
+		       || is_std_init_list (type)))
+	       /* This can happen for NSDMI in template class (c++/58930).  */ 
+	       || DIRECT_LIST_INIT_P (init)))
     {
       /* With references and list-initialization, we need to deal with
 	 extending temporary lifetimes.  12.2p5: "A temporary bound to a
Index: testsuite/g++.dg/cpp0x/nsdmi-template11.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template11.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template11.C	(working copy)
@@ -0,0 +1,15 @@
+// PR c++/58930
+// { dg-do compile { target c++11 } }
+
+struct SampleModule
+{
+  explicit SampleModule (int);
+};
+
+template < typename >
+struct BaseHandler
+{
+  SampleModule module_ { 0 };
+};
+
+BaseHandler<int> a;
Index: testsuite/g++.dg/cpp0x/nsdmi-template12.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template12.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template12.C	(working copy)
@@ -0,0 +1,17 @@
+// PR c++/58753
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+template <class T>
+struct X {X(std::initializer_list<int>) {}};
+
+template <class zomg> 
+class T {
+  X<T> x{1}; 
+}; 
+
+int main()
+{
+  T<int> t;
+}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++ Patch/RFC] PR 58753 & 58930
  2014-05-15 13:47 [C++ Patch/RFC] PR 58753 & 58930 Paolo Carlini
@ 2014-05-15 20:25 ` Paolo Carlini
  2014-05-19 18:28 ` Jason Merrill
  1 sibling, 0 replies; 8+ messages in thread
From: Paolo Carlini @ 2014-05-15 20:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

.. in case it would be useful to better analyze the issue and my 
tentative fix, I ran the C++ and C++ runtime testsuite with an 
appropriate gcc_assert, and the added DIRECT_LIST_INIT_P (init) case 
matters only for the existing cpp1y/pr58708.C (besides the new 
testcases, of course).

Also, in case it wasn't obvious in the other message, comparing 
c++/58930 as-is to the non-template version, it's clear that with the 
patchlet applied, both lead to similar TARGET_EXPRs from the initial 
CONSTRUCTOR produced by cp_parser_initializer.

Paolo.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++ Patch/RFC] PR 58753 & 58930
  2014-05-15 13:47 [C++ Patch/RFC] PR 58753 & 58930 Paolo Carlini
  2014-05-15 20:25 ` Paolo Carlini
@ 2014-05-19 18:28 ` Jason Merrill
  2014-05-19 20:20   ` Paolo Carlini
  2014-05-20 14:52   ` Paolo Carlini
  1 sibling, 2 replies; 8+ messages in thread
From: Jason Merrill @ 2014-05-19 18:28 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

How about doing digest_init in get_nsdmi, so that the conversion is also 
exposed to walk_field_subobs?

Jason

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++ Patch/RFC] PR 58753 & 58930
  2014-05-19 18:28 ` Jason Merrill
@ 2014-05-19 20:20   ` Paolo Carlini
  2014-05-20 14:52   ` Paolo Carlini
  1 sibling, 0 replies; 8+ messages in thread
From: Paolo Carlini @ 2014-05-19 20:20 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi,

> On 19/mag/2014, at 20:28, Jason Merrill <jason@redhat.com> wrote:
> 
> How about doing digest_init in get_nsdmi, so that the conversion is also exposed to walk_field_subobs?

Thanks, I'll look into that.

Paolo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++ Patch/RFC] PR 58753 & 58930
  2014-05-19 18:28 ` Jason Merrill
  2014-05-19 20:20   ` Paolo Carlini
@ 2014-05-20 14:52   ` Paolo Carlini
  2014-05-20 15:08     ` Jason Merrill
  1 sibling, 1 reply; 8+ messages in thread
From: Paolo Carlini @ 2014-05-20 14:52 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

Hi,

On 05/19/2014 08:28 PM, Jason Merrill wrote:
> How about doing digest_init in get_nsdmi, so that the conversion is 
> also exposed to walk_field_subobs?
Thus, good news: something as simple as the below passes testing, works 
for the 2 bugs and for c++/58704 too. Thus, what else? Personally, I'm 
not sure about a few things: whether reshape_init is needed (I tend to 
think so, because later in perform_member_init certainly we use it); 
whether digest_init (vs digest_init_flags, cmp the parser) is fine.

Thanks again!
Paolo.

//////////////////////

[-- Attachment #2: patch_58753_58930_58704_draft --]
[-- Type: text/plain, Size: 2742 bytes --]

Index: cp/init.c
===================================================================
--- cp/init.c	(revision 210641)
+++ cp/init.c	(working copy)
@@ -529,17 +529,28 @@ tree
 get_nsdmi (tree member, bool in_ctor)
 {
   tree init;
+  tree type = TREE_TYPE (member);
   tree save_ccp = current_class_ptr;
   tree save_ccr = current_class_ref;
   if (!in_ctor)
     inject_this_parameter (DECL_CONTEXT (member), TYPE_UNQUALIFIED);
   if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member))
-    /* Do deferred instantiation of the NSDMI.  */
-    init = (tsubst_copy_and_build
-	    (DECL_INITIAL (DECL_TI_TEMPLATE (member)),
-	     DECL_TI_ARGS (member),
-	     tf_warning_or_error, member, /*function_p=*/false,
-	     /*integral_constant_expression_p=*/false));
+    {
+      /* Do deferred instantiation of the NSDMI.  */
+      init = (tsubst_copy_and_build
+	      (DECL_INITIAL (DECL_TI_TEMPLATE (member)),
+	       DECL_TI_ARGS (member),
+	       tf_warning_or_error, member, /*function_p=*/false,
+	       /*integral_constant_expression_p=*/false));
+
+      if (TREE_TYPE (init) != type)
+	{
+	  if (BRACE_ENCLOSED_INITIALIZER_P (init)
+	      && CP_AGGREGATE_TYPE_P (type))
+	    init = reshape_init (type, init, tf_warning_or_error);
+	  init = digest_init (type, init, tf_warning_or_error);
+	}
+    }
   else
     {
       init = DECL_INITIAL (member);
Index: testsuite/g++.dg/cpp0x/nsdmi-template11.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template11.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template11.C	(working copy)
@@ -0,0 +1,15 @@
+// PR c++/58930
+// { dg-do compile { target c++11 } }
+
+struct SampleModule
+{
+  explicit SampleModule (int);
+};
+
+template < typename >
+struct BaseHandler
+{
+  SampleModule module_ { 0 };
+};
+
+BaseHandler<int> a;
Index: testsuite/g++.dg/cpp0x/nsdmi-template12.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template12.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template12.C	(working copy)
@@ -0,0 +1,17 @@
+// PR c++/58753
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+template <class T>
+struct X {X(std::initializer_list<int>) {}};
+
+template <class zomg> 
+class T {
+  X<T> x{1}; 
+}; 
+
+int main()
+{
+  T<int> t;
+}
Index: testsuite/g++.dg/cpp0x/nsdmi-template13.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template13.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template13.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/58704
+// { dg-do compile { target c++11 } }
+
+struct A {};
+
+template<typename> struct B
+{
+  A a[1] = { };
+};
+
+B<int> b;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++ Patch/RFC] PR 58753 & 58930
  2014-05-20 14:52   ` Paolo Carlini
@ 2014-05-20 15:08     ` Jason Merrill
  2014-05-20 16:15       ` Paolo Carlini
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2014-05-20 15:08 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

On 05/20/2014 10:50 AM, Paolo Carlini wrote:
> +      if (TREE_TYPE (init) != type)
> +	{
> +	  if (BRACE_ENCLOSED_INITIALIZER_P (init)
> +	      && CP_AGGREGATE_TYPE_P (type))
> +	    init = reshape_init (type, init, tf_warning_or_error);
> +	  init = digest_init (type, init, tf_warning_or_error);

Instead of this let's factor the relevant code out of 
cp_parser_late_parse_one_default_arg and use it here as well.  That is,

>           int flags = LOOKUP_IMPLICIT;
>           if (DIRECT_LIST_INIT_P (parsed_arg))
>             flags = LOOKUP_NORMAL;
>           parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags);
>           if (TREE_CODE (parsed_arg) == TARGET_EXPR)
>             /* This represents the whole initialization.  */
>             TARGET_EXPR_DIRECT_INIT_P (parsed_arg) = true;

Jason

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++ Patch/RFC] PR 58753 & 58930
  2014-05-20 15:08     ` Jason Merrill
@ 2014-05-20 16:15       ` Paolo Carlini
  2014-05-20 17:39         ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Carlini @ 2014-05-20 16:15 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]

Hi,

On 05/20/2014 05:08 PM, Jason Merrill wrote:
> On 05/20/2014 10:50 AM, Paolo Carlini wrote:
>> +      if (TREE_TYPE (init) != type)
>> +    {
>> +      if (BRACE_ENCLOSED_INITIALIZER_P (init)
>> +          && CP_AGGREGATE_TYPE_P (type))
>> +        init = reshape_init (type, init, tf_warning_or_error);
>> +      init = digest_init (type, init, tf_warning_or_error);
>
> Instead of this let's factor the relevant code out of 
> cp_parser_late_parse_one_default_arg and use it here as well.
Indeed. Thus I'm finishing testing the below.

Thanks,
Paolo.

///////////////////////////


[-- Attachment #2: CL_58753_58930_58704 --]
[-- Type: text/plain, Size: 518 bytes --]

/cp
2014-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58753
	PR c++/58930
	PR c++/58704
	* typeck2.c (digest_nsdmi_init): New.
	* parser.c (cp_parser_late_parse_one_default_arg): Use it.
	* init.c (get_nsdmi): Likewise.
	* cp-tree.h (digest_nsdmi_init): Declare.

/testsuite
2014-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58753
	PR c++/58930
	PR c++/58704
	* g++.dg/cpp0x/nsdmi-template11.C: New.
	* g++.dg/cpp0x/nsdmi-template12.C: Likewise.
	* g++.dg/cpp0x/nsdmi-template13.C: Likewise.

[-- Attachment #3: patch_58753_58930_58704 --]
[-- Type: text/plain, Size: 4664 bytes --]

Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 210645)
+++ cp/cp-tree.h	(working copy)
@@ -6172,6 +6172,7 @@ extern tree store_init_value			(tree, tree, vec<tr
 extern void check_narrowing			(tree, tree);
 extern tree digest_init				(tree, tree, tsubst_flags_t);
 extern tree digest_init_flags			(tree, tree, int);
+extern tree digest_nsdmi_init		        (tree, tree);
 extern tree build_scoped_ref			(tree, tree, tree *);
 extern tree build_x_arrow			(location_t, tree,
 						 tsubst_flags_t);
Index: cp/init.c
===================================================================
--- cp/init.c	(revision 210645)
+++ cp/init.c	(working copy)
@@ -534,12 +534,16 @@ get_nsdmi (tree member, bool in_ctor)
   if (!in_ctor)
     inject_this_parameter (DECL_CONTEXT (member), TYPE_UNQUALIFIED);
   if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member))
-    /* Do deferred instantiation of the NSDMI.  */
-    init = (tsubst_copy_and_build
-	    (DECL_INITIAL (DECL_TI_TEMPLATE (member)),
-	     DECL_TI_ARGS (member),
-	     tf_warning_or_error, member, /*function_p=*/false,
-	     /*integral_constant_expression_p=*/false));
+    {
+      /* Do deferred instantiation of the NSDMI.  */
+      init = (tsubst_copy_and_build
+	      (DECL_INITIAL (DECL_TI_TEMPLATE (member)),
+	       DECL_TI_ARGS (member),
+	       tf_warning_or_error, member, /*function_p=*/false,
+	       /*integral_constant_expression_p=*/false));
+
+      init = digest_nsdmi_init (member, init);
+    }
   else
     {
       init = DECL_INITIAL (member);
Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 210645)
+++ cp/parser.c	(working copy)
@@ -23681,15 +23681,7 @@ cp_parser_late_parse_one_default_arg (cp_parser *p
 	parsed_arg = check_default_argument (parmtype, parsed_arg,
 					     tf_warning_or_error);
       else
-	{
-	  int flags = LOOKUP_IMPLICIT;
-	  if (DIRECT_LIST_INIT_P (parsed_arg))
-	    flags = LOOKUP_NORMAL;
-	  parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags);
-	  if (TREE_CODE (parsed_arg) == TARGET_EXPR)
-	    /* This represents the whole initialization.  */
-	    TARGET_EXPR_DIRECT_INIT_P (parsed_arg) = true;
-	}
+	parsed_arg = digest_nsdmi_init (decl, parsed_arg);
     }
 
   /* If the token stream has not been completely used up, then
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 210645)
+++ cp/typeck2.c	(working copy)
@@ -1114,6 +1114,22 @@ digest_init_flags (tree type, tree init, int flags
 {
   return digest_init_r (type, init, false, flags, tf_warning_or_error);
 }
+
+/* Process the initializer INIT for an NSDMI DECL (a FIELD_DECL).  */
+tree
+digest_nsdmi_init (tree decl, tree init)
+{
+  gcc_assert (TREE_CODE (decl) == FIELD_DECL);
+
+  int flags = LOOKUP_IMPLICIT;
+  if (DIRECT_LIST_INIT_P (init))
+    flags = LOOKUP_NORMAL;
+  init = digest_init_flags (TREE_TYPE (decl), init, flags);
+  if (TREE_CODE (init) == TARGET_EXPR)
+    /* This represents the whole initialization.  */
+    TARGET_EXPR_DIRECT_INIT_P (init) = true;
+  return init;
+}
 \f
 /* Set of flags used within process_init_constructor to describe the
    initializers.  */
Index: testsuite/g++.dg/cpp0x/nsdmi-template11.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template11.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template11.C	(working copy)
@@ -0,0 +1,15 @@
+// PR c++/58930
+// { dg-do compile { target c++11 } }
+
+struct SampleModule
+{
+  explicit SampleModule (int);
+};
+
+template < typename >
+struct BaseHandler
+{
+  SampleModule module_ { 0 };
+};
+
+BaseHandler<int> a;
Index: testsuite/g++.dg/cpp0x/nsdmi-template12.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template12.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template12.C	(working copy)
@@ -0,0 +1,17 @@
+// PR c++/58753
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+template <class T>
+struct X {X(std::initializer_list<int>) {}};
+
+template <class zomg> 
+class T {
+  X<T> x{1}; 
+}; 
+
+int main()
+{
+  T<int> t;
+}
Index: testsuite/g++.dg/cpp0x/nsdmi-template13.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template13.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template13.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/58704
+// { dg-do compile { target c++11 } }
+
+struct A {};
+
+template<typename> struct B
+{
+  A a[1] = { };
+};
+
+B<int> b;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++ Patch/RFC] PR 58753 & 58930
  2014-05-20 16:15       ` Paolo Carlini
@ 2014-05-20 17:39         ` Jason Merrill
  0 siblings, 0 replies; 8+ messages in thread
From: Jason Merrill @ 2014-05-20 17:39 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-05-20 17:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-15 13:47 [C++ Patch/RFC] PR 58753 & 58930 Paolo Carlini
2014-05-15 20:25 ` Paolo Carlini
2014-05-19 18:28 ` Jason Merrill
2014-05-19 20:20   ` Paolo Carlini
2014-05-20 14:52   ` Paolo Carlini
2014-05-20 15:08     ` Jason Merrill
2014-05-20 16:15       ` Paolo Carlini
2014-05-20 17:39         ` 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).