This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR preprocessor/33305: Warn for empty macro arguments


Andrew Haley wrote:
> Kaveh R. GHAZI wrote:
>> On Wed, 11 Jun 2008, Andrew Haley wrote:
>>
>>> C_COMMON_FIXED_TYPES uses empty macro arguments, which aren't defined in C89.
>>>
>>> I can't see any way to fix this that's better than defining a pair of macros.
>>> Does anyone have any better ideas?
>>>
>>> Andrew.
>>>
>>>
>>>
>>> 2008-06-11  Andrew Haley  <aph@littlepinkcloud.com>
>>>
>>> 	* c-common.c (C_COMMON_FIXED_TYPES_SAT): New macro.
>>> 	(C_COMMON_FIXED_TYPES_SAT): New macro.
>>> 	(C_COMMON_FIXED_TYPES): Remove first arg.
>>> 	(C_COMMON_FIXED_MODE_TYPES): Likewise.
>> I suspect this might partially fix PR bootstrap/33304.  If so, I would
>> like to see it on the 4.3.x branch also.  Oh and you listed
>> C_COMMON_FIXED_TYPES_SAT twice in the ChangeLog.
>>
>> My hope is that we could warn about empty macro arguments in C90 mode.
>> Would you like to pursue this as an enhancement?  PR preprocessor/33305.
>> :-)

The easiest place to detect this is at expansion time.  This prints the
file and line number at the point the macro is expanded and it also names
the macro and the arg, to help with debugging.  This has revealed a few places
in the gcc source where we use empty macro arguments, and I'll follow up with
a patch for those.

Andrew.


2008-06-13  Andrew Haley  <aph@redhat.com>

	PR preprocessor/33305:
	* macro.c (replace_args): Print a warning for empty macro
	arguments in C89.

Index: macro.c
===================================================================
--- macro.c	(revision 135765)
+++ macro.c	(working copy)
@@ -1009,6 +1009,15 @@
 	  if (src->flags & PASTE_LEFT)
 	    paste_flag = dest - 1;
 	}
+      else if (! CPP_OPTION (pfile, c99)
+	       && ! cpp_in_system_header (pfile))
+	{
+	  cpp_error (pfile, CPP_DL_WARNING,
+		     "in macro %s arg %d: "
+		     "empty macro arguments are undefined in C89",
+		     NODE_NAME (node),
+		     src->val.arg_no);
+	}

       /* Avoid paste on RHS (even case count == 0).  */
       if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]