c-typeck.c (c_build_va_arg): Clarify the error message.
authorMarek Polacek <polacek@redhat.com>
Thu, 30 Apr 2015 13:35:44 +0000 (13:35 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 30 Apr 2015 13:35:44 +0000 (13:35 +0000)
* c-typeck.c (c_build_va_arg): Clarify the error message.

* gcc.dg/pr65901.c (foo): Adjust dg-error.
* gcc.c-torture/compile/pr48767.c (foo): Likewise.

From-SVN: r222626

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr48767.c
gcc/testsuite/gcc.dg/pr65901.c

index 3894bb9..2ef895a 100644 (file)
@@ -6,6 +6,8 @@
        * c-typeck.c (c_incomplete_type_error): Refactor to use %qT.  Print
        the type of a decl.
 
+       * c-typeck.c (c_build_va_arg): Clarify the error message.
+
 2015-04-29  Thomas Schwinge  <thomas@codesourcery.com>
 
        * c-parser.c (c_parser_oacc_enter_exit_data): Use
index 413cd07..328f294 100644 (file)
@@ -12635,14 +12635,17 @@ c_build_qualified_type (tree type, int type_quals)
 tree
 c_build_va_arg (location_t loc, tree expr, tree type)
 {
-  if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
-    warning_at (loc, OPT_Wc___compat,
-               "C++ requires promoted type, not enum type, in %<va_arg%>");
-  if (type == error_mark_node || !COMPLETE_TYPE_P (type))
+  if (error_operand_p (type))
+    return error_mark_node;
+  else if (!COMPLETE_TYPE_P (type))
     {
-      c_incomplete_type_error (NULL_TREE, type);
+      error_at (loc, "second argument to %<va_arg%> is of incomplete "
+               "type %qT", type);
       return error_mark_node;
     }
+  else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
+    warning_at (loc, OPT_Wc___compat,
+               "C++ requires promoted type, not enum type, in %<va_arg%>");
   return build_va_arg (loc, expr, type);
 }
 
index 4557768..3ab0afe 100644 (file)
@@ -2,6 +2,9 @@
 
        * c-c++-common/Wbool-compare-3.c: New test.
 
+       * gcc.dg/pr65901.c (foo): Adjust dg-error.
+       * gcc.c-torture/compile/pr48767.c (foo): Likewise.
+
 2015-04-30  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/57610
index c8fef35..f504fe0 100644 (file)
@@ -3,5 +3,5 @@
 void
 foo (__builtin_va_list ap)
 {
-  __builtin_va_arg (ap, void);  /* { dg-error "invalid use of void expression" } */
+  __builtin_va_arg (ap, void); /* { dg-error "second argument to .va_arg. is of incomplete type .void." } */
 }
index 8708a1e..b40eea3 100644 (file)
@@ -9,8 +9,8 @@ union U;
 void
 foo (__builtin_va_list ap)
 {
-  __builtin_va_arg (ap, void);  /* { dg-error "invalid use of void expression" } */
-  __builtin_va_arg (ap, struct S);  /* { dg-error "invalid use of undefined type" } */
-  __builtin_va_arg (ap, enum E);  /* { dg-error "invalid use of undefined type" } */
-  __builtin_va_arg (ap, union U);  /* { dg-error "invalid use of undefined type" } */
+  __builtin_va_arg (ap, void);  /* { dg-error "second argument to .va_arg. is of incomplete type .void." } */
+  __builtin_va_arg (ap, struct S);  /* { dg-error "second argument to .va_arg. is of incomplete type .struct S." } */
+  __builtin_va_arg (ap, enum E);  /* { dg-error "second argument to .va_arg. is of incomplete type .enum E." } */
+  __builtin_va_arg (ap, union U);  /* { dg-error "second argument to .va_arg. is of incomplete type .union U." } */
 }