>Submitter-Id:  net
>Originator:    Matthias Klose
>Organization:  
>Confidential:  no
>Synopsis:      _Pragma within macros is improperly expanded
>Severity:      serious
>Priority:      medium
>Category:      preprocessor
>Class:         sw-bug
>Release:       3.2.1 2002-11-03
>Environment:
System: Linux smile 2.4.18-xfs #1 Tue Mar 12 22:42:02 CET 2002 i686 unknown
Architecture: i686

        
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
>Description:
The original report from the Debian BTS, fix applied to head and branch:

[EMAIL PROTECTED]:~$ cat foo.c
_Pragma("foo"); int y;
#define FOO _Pragma("foo"); int x;
FOO
[EMAIL PROTECTED]:~$ cpp-3.2 foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"

# 1 "foo.c"
#pragma foo 
# 1 "foo.c"
             ; int y;


# 3 "foo.c"
#pragma ; int x;foo 

The first line is expanded correctly; the third is not (rendering
_Pragma almost completely useless).


Fixed by Neil:
        * cpphash.h (FIRST, LAST, CUR, RLIMIT): Fix definitions.
        * cpplib.c (destringize_and_run): Kludge around getting
        tokens from in-progress macros.
        (_cpp_do__Pragma): Simplify. testsuite:
        * gcc.dg/cpp/_Pragma4.c: New test.

Bug submitter claims:

Nope, still not right. Here's a new case where it breaks:

[EMAIL PROTECTED]:~/tmp$ cat foo.c
#define ALPHA(A) alpha_ ## A
#define BETA(B) beta_ ## B
#define GAMMA(C) _Pragma("moose") ALPHA(C) BETA(C)
GAMMA(baz);
[EMAIL PROTECTED]:~/tmp$ cpp-3.2 foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"




# 4 "foo.c"
#pragma moose=20
# 4 "foo.c"
alpha_baz beta_alpha_baz;
[EMAIL PROTECTED]:~/tmp$ cpp-2.95 foo.c
# 1 "foo.c"



_Pragma("moose") alpha_baz    beta_baz    ;
=3D=3D

Note how beta_baz has become beta_alpha_baz in 3.2. This only happens
when the _Pragma is present, so I presume it's the same bug in another
form.

But wait! It gets better:

[EMAIL PROTECTED]:~/tmp$ cat foo.c
#define ALPHA
#define BETA(B) beta_ ## B
#define GAMMA(C) _Pragma("moose") ALPHA BETA(C)
GAMMA(baz);
[EMAIL PROTECTED]:~/tmp$ cpp-3.2 foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"




# 4 "foo.c"
#pragma moose=20
# 4 "foo.c"
cpp-3.2: Internal error: Aborted (program cpp0)
Please submit a full bug report.

>How-To-Repeat:
        
>Fix:
        


Reply via email to