Bug#154767: cpp-2.95: cpp fails to parse macros with varargs correctly
Package: cpp-2.95
Version: 1:2.95.4-10
Severity: important
Given the sample code (extracted from the Linux kernel sources):
#include <stdio.h>
#define DRM_NAME "drm"
#define KERN_ERR "<7>"
#define DRM_ERROR(fmt, args...) \
printf(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__, ##
args)
int main()
{
DRM_ERROR( "test\n" );
return 0;
}
cpp produces the following code for the main() function:
int main()
{
printf("<7>" "[" "drm" ":%s] *ERROR* " "test\n" , ) ;
return 0;
}
which is incorrect according to the info docs:
The reason for using ##' is to handle the case when args' matches
no arguments at all. In this case, args' has an empty value. In this
case, the second comma in the definition becomes an embarrassment: if
it got through to the expansion of the macro, we would get something
like this:
fprintf (stderr, "success!\n" , )
which is invalid C syntax. ##' gets rid of the comma, so we get the
following instead:
fprintf (stderr, "success!\n")
Which is not the case. That bug breaks the compile of the 2.4.19-rc3-ac4
kernel (the DRM tree). Both cpp 3.0 and 3.1 work correctly.
-- System Information
Debian Release: testing/unstable
Kernel Version: Linux beowulf 2.4.19-rc3-ac3 #1 Sat Jul 27 21:42:48 CEST 2002 i686 unknown unknown GNU/Linux
Versions of the packages cpp-2.95 depends on:
ii cpp 2.95.4-15 The GNU C preprocessor.
ii libc6 2.2.5-12 GNU C Library: Shared libraries and Timezone data
--
To UNSUBSCRIBE, email to debian-gcc-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to: