public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] unify c/c++ error handling for simple indirections
@ 2010-12-09 18:30 Nathan Froyd
  2010-12-09 21:38 ` Joseph S. Myers
  2010-12-09 22:03 ` Gabriel Dos Reis
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Froyd @ 2010-12-09 18:30 UTC (permalink / raw)
  To: gcc-patches

For whatever reason, the C and C++ front-ends report invalid
indirections in different ways.  The patch below unifies them into a
common routine, invalid_indirection_error.  This change has the pleasant
side-effect of printing out type information in the C++ front-end for
such errors.  If folks want to change the error messages later, it also
becomes somewhat easier.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

gcc/
	* c-typeck.c (build_indirect_ref): Call invalid_indirection_error.

gcc/c-family/
	* c-common.h (invalid_indirection_error): Declare.
	* c-common.c (invalid_indirection_error): Define.

gcc/cp/
	* typeck.c (cp_build_indirect_ref): Call invalid_indirection_error.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 7a57838..b3d0ea5 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -8585,6 +8585,42 @@ lvalue_error (enum lvalue_use use)
       gcc_unreachable ();
     }
 }
+
+/* Print an error message for an invalid indirection of type TYPE.
+   ERRSTRING is the name of the operator for the indirection.  */
+
+void
+invalid_indirection_error (location_t loc, tree type, ref_operator errstring)
+{
+  switch (errstring)
+    {
+    case RO_NULL:
+      error_at (loc, "invalid type argument (have %qT)", type);
+      break;
+    case RO_ARRAY_INDEXING:
+      error_at (loc,
+		"invalid type argument of array indexing (have %qT)",
+		type);
+      break;
+    case RO_UNARY_STAR:
+      error_at (loc,
+		"invalid type argument of unary %<*%> (have %qT)",
+		type);
+      break;
+    case RO_ARROW:
+      error_at (loc,
+		"invalid type argument of %<->%> (have %qT)",
+		type);
+      break;
+    case RO_IMPLICIT_CONVERSION:
+      error_at (loc,
+		"invalid type argument of implicit conversion (have %qT)",
+		type);
+      break;
+    default:
+      gcc_unreachable ();
+    }
+}
 \f
 /* *PTYPE is an incomplete array.  Complete it with a domain based on
    INITIAL_VALUE.  If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 928e502..b6f8d39 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -929,6 +929,7 @@ enum lvalue_use {
 };
 
 extern void lvalue_error (enum lvalue_use);
+extern void invalid_indirection_error (location_t, tree, ref_operator);
 
 extern int complete_array_type (tree *, tree, bool);
 
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 7bba44e..cbe9f20 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2267,26 +2267,8 @@ build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
 	}
     }
   else if (TREE_CODE (pointer) != ERROR_MARK)
-    switch (errstring)
-      {
-         case RO_ARRAY_INDEXING:
-           error_at (loc,
-                     "invalid type argument of array indexing (have %qT)",
-                     type);
-           break;
-         case RO_UNARY_STAR:
-           error_at (loc,
-                     "invalid type argument of unary %<*%> (have %qT)",
-                     type);
-           break;
-         case RO_ARROW:
-           error_at (loc,
-                     "invalid type argument of %<->%> (have %qT)",
-                     type);
-           break;
-         default:
-           gcc_unreachable ();
-      }
+    invalid_indirection_error (loc, type, errstring);
+
   return error_mark_node;
 }
 
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 7416f09..fc9ad7d 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2804,23 +2804,8 @@ cp_build_indirect_ref (tree ptr, ref_operator errorstring,
            gcc_unreachable ();
       }
   else if (pointer != error_mark_node)
-    switch (errorstring)
-      {
-         case RO_NULL:
-           error ("invalid type argument");
-           break;
-         case RO_ARRAY_INDEXING:
-           error ("invalid type argument of array indexing");
-           break;
-         case RO_UNARY_STAR:
-           error ("invalid type argument of unary %<*%>");
-           break;
-         case RO_IMPLICIT_CONVERSION:
-           error ("invalid type argument of implicit conversion");
-           break;
-         default:
-           gcc_unreachable ();
-      }
+    invalid_indirection_error (input_location, type, errorstring);
+
   return error_mark_node;
 }
 

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

* Re: [PATCH] unify c/c++ error handling for simple indirections
  2010-12-09 18:30 [PATCH] unify c/c++ error handling for simple indirections Nathan Froyd
@ 2010-12-09 21:38 ` Joseph S. Myers
  2010-12-09 22:03 ` Gabriel Dos Reis
  1 sibling, 0 replies; 3+ messages in thread
From: Joseph S. Myers @ 2010-12-09 21:38 UTC (permalink / raw)
  To: Nathan Froyd; +Cc: gcc-patches

On Thu, 9 Dec 2010, Nathan Froyd wrote:

> gcc/
> 	* c-typeck.c (build_indirect_ref): Call invalid_indirection_error.
> 
> gcc/c-family/
> 	* c-common.h (invalid_indirection_error): Declare.
> 	* c-common.c (invalid_indirection_error): Define.

The C changes are OK with the addition of gcc_assert (c_dialect_cxx ()) in 
the RO_NULL case.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH] unify c/c++ error handling for simple indirections
  2010-12-09 18:30 [PATCH] unify c/c++ error handling for simple indirections Nathan Froyd
  2010-12-09 21:38 ` Joseph S. Myers
@ 2010-12-09 22:03 ` Gabriel Dos Reis
  1 sibling, 0 replies; 3+ messages in thread
From: Gabriel Dos Reis @ 2010-12-09 22:03 UTC (permalink / raw)
  To: Nathan Froyd; +Cc: gcc-patches

On Thu, Dec 9, 2010 at 12:16 PM, Nathan Froyd <froydnj@codesourcery.com> wrote:
> For whatever reason, the C and C++ front-ends report invalid
> indirections in different ways.  The patch below unifies them into a
> common routine, invalid_indirection_error.  This change has the pleasant
> side-effect of printing out type information in the C++ front-end for
> such errors.  If folks want to change the error messages later, it also
> becomes somewhat easier.
>
> Tested on x86_64-unknown-linux-gnu.  OK to commit?

OK.

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

end of thread, other threads:[~2010-12-09 21:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-09 18:30 [PATCH] unify c/c++ error handling for simple indirections Nathan Froyd
2010-12-09 21:38 ` Joseph S. Myers
2010-12-09 22:03 ` Gabriel Dos Reis

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).