Commit ac9f18db by Marek Polacek Committed by Marek Polacek

c-typeck.c (c_incomplete_type_error): Refactor to use %qT.

	* c-typeck.c (c_incomplete_type_error): Refactor to use %qT.  Print
	the type of a decl.

	* gcc.dg/incomplete-typedef-1.c: New test.

From-SVN: r222614
parent 9babc352
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
* c-typeck.c (set_init_label): Call error_at instead of error and * c-typeck.c (set_init_label): Call error_at instead of error and
pass LOC to it. pass LOC to it.
* c-typeck.c (c_incomplete_type_error): Refactor to use %qT. Print
the type of a decl.
2015-04-29 Thomas Schwinge <thomas@codesourcery.com> 2015-04-29 Thomas Schwinge <thomas@codesourcery.com>
* c-parser.c (c_parser_oacc_enter_exit_data): Use * c-parser.c (c_parser_oacc_enter_exit_data): Use
......
...@@ -229,15 +229,13 @@ require_complete_type (tree value) ...@@ -229,15 +229,13 @@ require_complete_type (tree value)
void void
c_incomplete_type_error (const_tree value, const_tree type) c_incomplete_type_error (const_tree value, const_tree type)
{ {
const char *type_code_string;
/* Avoid duplicate error message. */ /* Avoid duplicate error message. */
if (TREE_CODE (type) == ERROR_MARK) if (TREE_CODE (type) == ERROR_MARK)
return; return;
if (value != 0 && (TREE_CODE (value) == VAR_DECL if (value != 0 && (TREE_CODE (value) == VAR_DECL
|| TREE_CODE (value) == PARM_DECL)) || TREE_CODE (value) == PARM_DECL))
error ("%qD has an incomplete type", value); error ("%qD has an incomplete type %qT", value, type);
else else
{ {
retry: retry:
...@@ -246,15 +244,8 @@ c_incomplete_type_error (const_tree value, const_tree type) ...@@ -246,15 +244,8 @@ c_incomplete_type_error (const_tree value, const_tree type)
switch (TREE_CODE (type)) switch (TREE_CODE (type))
{ {
case RECORD_TYPE: case RECORD_TYPE:
type_code_string = "struct";
break;
case UNION_TYPE: case UNION_TYPE:
type_code_string = "union";
break;
case ENUMERAL_TYPE: case ENUMERAL_TYPE:
type_code_string = "enum";
break; break;
case VOID_TYPE: case VOID_TYPE:
...@@ -280,11 +271,10 @@ c_incomplete_type_error (const_tree value, const_tree type) ...@@ -280,11 +271,10 @@ c_incomplete_type_error (const_tree value, const_tree type)
} }
if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
error ("invalid use of undefined type %<%s %E%>", error ("invalid use of undefined type %qT", type);
type_code_string, TYPE_NAME (type));
else else
/* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
error ("invalid use of incomplete typedef %qD", TYPE_NAME (type)); error ("invalid use of incomplete typedef %qT", type);
} }
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
* gcc.dg/init-bad-8.c: New test. * gcc.dg/init-bad-8.c: New test.
* gcc.dg/incomplete-typedef-1.c: New test.
2015-04-30 Paolo Carlini <paolo.carlini@oracle.com> 2015-04-30 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/59955 PR c++/59955
......
/* { dg-do compile } */
/* { dg-options "" } */
typedef struct S TS;
typedef union U TU;
void
foo (void)
{
(TS) { }; /* { dg-error "invalid use of incomplete typedef" } */
(TU) { }; /* { dg-error "invalid use of incomplete typedef" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment