public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] Fix finish_switch_cond location
@ 2019-08-23 10:44 Paolo Carlini
  2019-08-23 22:10 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2019-08-23 10:44 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi,

a rather straightforward tweak. We could imagine much more heavily 
reworking the code to avoid saving the original condition 
(build_expr_type_conversion return NULL_TREE upon error), I'm not sure 
if it's worth it. Tested x86_64-linux.

Thanks, Paolo.

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


[-- Attachment #2: CL_locs_43 --]
[-- Type: text/plain, Size: 249 bytes --]

/cp
2019-08-23  Paolo Carlini  <paolo.carlini@oracle.com>

	* semantics.c (finish_switch_cond): Improve error message location.

/testsuite
2019-08-23  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/conversion/simd4.C: Test all the locations.

[-- Attachment #3: patch_locs_43 --]
[-- Type: text/plain, Size: 2373 bytes --]

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 274845)
+++ cp/semantics.c	(working copy)
@@ -1185,10 +1185,12 @@ finish_switch_cond (tree cond, tree switch_stmt)
   if (!processing_template_decl)
     {
       /* Convert the condition to an integer or enumeration type.  */
+      tree orig_cond = cond;
       cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
       if (cond == NULL_TREE)
 	{
-	  error ("switch quantity not an integer");
+	  error_at (cp_expr_loc_or_input_loc (orig_cond),
+		    "switch quantity not an integer");
 	  cond = error_mark_node;
 	}
       /* We want unlowered type here to handle enum bit-fields.  */
Index: testsuite/g++.dg/conversion/simd4.C
===================================================================
--- testsuite/g++.dg/conversion/simd4.C	(revision 274845)
+++ testsuite/g++.dg/conversion/simd4.C	(working copy)
@@ -20,15 +20,15 @@ foo ()
   v[b];		// { dg-error "4:invalid types" }
   w[b];		// { dg-error "4:invalid types" }
   new int[t];
-  new int[u];	// { dg-error "new-declarator must have integral" }
-  new int[v];	// { dg-error "new-declarator must have integral" }
-  new int[w];	// { dg-error "new-declarator must have integral" }
+  new int[u];	// { dg-error "11:expression in new-declarator must have integral" }
+  new int[v];	// { dg-error "11:expression in new-declarator must have integral" }
+  new int[w];	// { dg-error "11:expression in new-declarator must have integral" }
   switch (t) { default: break; }
-  switch (u) { default: break; }	// { dg-error "switch quantity not an integer" }
-  switch (v) { default: break; }	// { dg-error "switch quantity not an integer" }
-  switch (w) { default: break; }	// { dg-error "switch quantity not an integer" }
+  switch (u) { default: break; }	// { dg-error "11:switch quantity not an integer" }
+  switch (v) { default: break; }	// { dg-error "11:switch quantity not an integer" }
+  switch (w) { default: break; }	// { dg-error "11:switch quantity not an integer" }
   t = ~t;
-  u = ~u;	// { dg-error "wrong type argument to bit-complement" }
+  u = ~u;	// { dg-error "8:wrong type argument to bit-complement" }
   v = ~v;
-  w = ~w;	// { dg-error "wrong type argument to bit-complement" }
+  w = ~w;	// { dg-error "8:wrong type argument to bit-complement" }
 }

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

* Re: [C++ Patch] Fix finish_switch_cond location
  2019-08-23 10:44 [C++ Patch] Fix finish_switch_cond location Paolo Carlini
@ 2019-08-23 22:10 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-08-23 22:10 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

On 8/23/19 2:54 AM, Paolo Carlini wrote:
> Hi,
> 
> a rather straightforward tweak. We could imagine much more heavily 
> reworking the code to avoid saving the original condition 
> (build_expr_type_conversion return NULL_TREE upon error), I'm not sure 
> if it's worth it. Tested x86_64-linux.

OK.

Jason

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

end of thread, other threads:[~2019-08-23 21:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-23 10:44 [C++ Patch] Fix finish_switch_cond location Paolo Carlini
2019-08-23 22:10 ` 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).