This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 27270 (reprise)


In the course of backporting the patch for PR 27270 to the 4.1 branch,
I realized it had broken g++.dg/template/ctor1.C, and that I had
failed to take note of that during testing.  This patch fixes that.

I realized that we should just use the general pattern that, during
template substitution we handle things as we would during normal
processing.  So, we now just call finish_compound_literal from tsubst,
and all's well.  This change also causes us to detect an error in
g++.dg/template/complit1.C that we didn't notice previously in
templates, but did catch in ordinary functions.

Tested on x86_64-unknown-linux-gnu.  I will apply this patch on top of
the previous patch on the 4.1 branch.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-10-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/27270
	* decl.c (reshape_init_class): Move check for designated
	to ...
	* parser.c (cp_parser_initializer_list): ... here.
	* pt.c (tsubst_copy_and_build): Use finish_compound_literal.

2006-10-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/27270
	* g++.dg/ext/complit8.C: Tweak error markers.
	* g++.dg/template/complit1.C: Add error marker.

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 117789)
+++ gcc/cp/decl.c	(working copy)
@@ -4485,9 +4485,6 @@ reshape_init_class (tree type, reshape_i
       /* Handle designated initializers, as an extension.  */
       if (d->cur->index)
 	{
-	  if (pedantic)
-	    pedwarn ("ISO C++ does not allow designated initializers");
-
 	  field = lookup_field_1 (type, d->cur->index, /*want_type=*/false);
 
 	  if (!field || TREE_CODE (field) != FIELD_DECL)
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 117814)
+++ gcc/cp/pt.c	(working copy)
@@ -9323,7 +9323,6 @@ tsubst_copy_and_build (tree t,
 	VEC(constructor_elt,gc) *n;
 	constructor_elt *ce;
 	unsigned HOST_WIDE_INT idx;
-	tree r;
 	tree type = tsubst (TREE_TYPE (t), args, complain, in_decl);
 	bool process_index_p;
 
@@ -9347,15 +9346,10 @@ tsubst_copy_and_build (tree t,
 	    ce->value = RECUR (ce->value);
 	  }
 
-	r = build_constructor (NULL_TREE, n);
-	TREE_HAS_CONSTRUCTOR (r) = TREE_HAS_CONSTRUCTOR (t);
+	if (TREE_HAS_CONSTRUCTOR (t))
+	  return finish_compound_literal (type, n);
 
-	if (type)
-	  {
-	    r = reshape_init (type, r);
-	    return digest_init (type, r);
-	  }
-	return r;
+	return build_constructor (NULL_TREE, n);
       }
 
     case TYPEID_EXPR:
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 117800)
+++ gcc/cp/parser.c	(working copy)
@@ -12736,6 +12784,9 @@ cp_parser_initializer_list (cp_parser* p
 	  && cp_lexer_next_token_is (parser->lexer, CPP_NAME)
 	  && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_COLON)
 	{
+	  /* Warn the user that they are using an extension.  */
+	  if (pedantic)
+	    pedwarn ("ISO C++ does not allow designated initializers");
 	  /* Consume the identifier.  */
 	  identifier = cp_lexer_consume_token (parser->lexer)->value;
 	  /* Consume the `:'.  */

Index: gcc/testsuite/g++.dg/ext/complit8.C
===================================================================
--- gcc/testsuite/g++.dg/ext/complit8.C	(revision 117814)
+++ gcc/testsuite/g++.dg/ext/complit8.C	(working copy)
@@ -5,7 +5,7 @@ template<typename Entry>
 struct Array {
   Entry *array[32];
   Array () :
-    array ( (Entry*[1]) { 0, 0 } ) // { dg-error "initializers|conversion" }
+    array ( (Entry*[1]) { 0, 0 } ) // { dg-error "initializers|incompatible" }
   {}
 };
 
Index: gcc/testsuite/g++.dg/template/complit1.C
===================================================================
--- gcc/testsuite/g++.dg/template/complit1.C	(revision 117789)
+++ gcc/testsuite/g++.dg/template/complit1.C	(working copy)
@@ -6,6 +6,6 @@ template <int D> struct C {
 };
 
 template<int D>
-C<D>::C() : d((int[]){1,2,3}) {}
+C<D>::C() : d((int[]){1,2,3}) {} // { dg-error "array" }
 
 template class C<1>;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]