public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 84632 ("[8 Regression] internal compiler error: tree check: expected record_type or union_type or qual_union_type, have array_type in reduced_constant_expression_p...")
@ 2018-03-22  8:12 Paolo Carlini
  2018-03-22 18:11 ` Jason Merrill
  0 siblings, 1 reply; 14+ messages in thread
From: Paolo Carlini @ 2018-03-22  8:12 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi,

yesterday I figured out that this issue is in fact orthogonal to 
possible improvements to maybe_deduce_size_from_array_init, indeed it 
happens also when we are not deducing the size. The testcase is very 
similar to that recently submitted for c++/78345, which led Jason to add 
the bit of additional checking around the middle of build_aggr_init. 
Since we did already have a similar check a bit earlier - not requiring 
the computation of from_array - I added one for VAR_DECLs too in the 
same place and tweaked/improved a bit the error message in the process 
(a few greps revealed that we don't seem to have any other generic error 
message using the form "bad ..."), consistently with the diagnostic that 
we already provide for, eg, a simple

     int a[2] = a;

FYI, I must also add that entire testsuite doesn't have a test 
triggering the existing TREE_CODE (init) == TREE_LIST check, and failed 
so far to construct one... (many such issues are normally catched by 
digest_init). Tested x86_64-linux.

Thanks, Paolo.

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



[-- Attachment #2: CL_84632 --]
[-- Type: text/plain, Size: 251 bytes --]

/cp
2018-03-22  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/84632
	* init.c (build_aggr_init): Reject VAR_DECLs too as initializer.

/testsuite
2018-03-22  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/84632
	* g++.dg/init/array49.C: New.

[-- Attachment #3: patch_84632 --]
[-- Type: text/plain, Size: 1298 bytes --]

Index: cp/init.c
===================================================================
--- cp/init.c	(revision 258745)
+++ cp/init.c	(working copy)
@@ -1688,12 +1688,14 @@ build_aggr_init (tree exp, tree init, int flags, t
 	}
       else
 	{
-	  /* An array may not be initialized use the parenthesized
-	     initialization form -- unless the initializer is "()".  */
-	  if (init && TREE_CODE (init) == TREE_LIST)
+	  /* An array may not be initialized usinge the parenthesized
+	     initialization form -- unless the initializer is "()".  
+	     Also reject VAR_DECLs (c++/84632).  */
+	  if (init && (TREE_CODE (init) == TREE_LIST || VAR_P (init)))
 	    {
 	      if (complain & tf_error)
-		error ("bad array initializer");
+		error_at (init_loc, "array must be initialized "
+			  "with a brace-enclosed initializer");
 	      return error_mark_node;
 	    }
 	  /* Must arrange to initialize each element of EXP
Index: testsuite/g++.dg/init/array49.C
===================================================================
--- testsuite/g++.dg/init/array49.C	(nonexistent)
+++ testsuite/g++.dg/init/array49.C	(working copy)
@@ -0,0 +1,6 @@
+// PR c++/84632
+// { dg-additional-options "-w" }
+
+class {
+  &a;  // { dg-error "forbids declaration" }
+} b[2] = b;  // { dg-error "initialized" }

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

end of thread, other threads:[~2018-03-26 18:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-22  8:12 [C++ Patch] PR 84632 ("[8 Regression] internal compiler error: tree check: expected record_type or union_type or qual_union_type, have array_type in reduced_constant_expression_p...") Paolo Carlini
2018-03-22 18:11 ` Jason Merrill
2018-03-22 19:04   ` Paolo Carlini
2018-03-22 21:19     ` Paolo Carlini
2018-03-22 21:30       ` Jason Merrill
2018-03-22 21:39         ` Paolo Carlini
2018-03-22 22:26           ` Paolo Carlini
2018-03-22 22:35             ` Jason Merrill
2018-03-23 10:48               ` Paolo Carlini
2018-03-23 12:45                 ` Jason Merrill
2018-03-26 10:30                   ` Paolo Carlini
2018-03-26 17:17                     ` Jason Merrill
2018-03-26 18:25                       ` Paolo Carlini
2018-03-26 18:33                         ` 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).