This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
preprocessor/2706: #defines expanded when -fpreprocessed given
- To: gcc-gnats at gcc dot gnu dot org
- Subject: preprocessor/2706: #defines expanded when -fpreprocessed given
- From: nathan at codesourcery dot com
- Date: 1 May 2001 13:38:19 -0000
- Reply-To: nathan at codesourcery dot com
>Number: 2706
>Category: preprocessor
>Synopsis: #defines expanded when -fpreprocessed given
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: accepts-illegal
>Submitter-Id: net
>Arrival-Date: Tue May 01 06:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Nathan
>Release: 1May2001 CVS 3.1 and 3.0
>Organization:
>Environment:
>Description:
the attached source is ill-formed, however it is accepted
as cpp appears to expand HASH to # and then process
the resultant #define. To make things more confusing
when rereading the preprocessed source , the #defines are
again expanded. This is a 2.95 regression and will be
a real headache to anybody trying to track down obsucre
preprocessor related problems in their source!
There appear to be 3 bugs, but could all have the same
cause.
1) a line is macro expanded and the result interpretted
for preprocessor directives
2) no diagnostic is issued for finding something like
#define in a preprocessed source
3) macros are expanded in preprocessed source.
current tree gives,
nathan@uha:275>./g++ -B ./ -save-temps current/cpp.C -c
nathan@uha:276>more cpp.ii
# 2 "current/cpp.C"
# define X "string"
# include "thing"
char const *foo ()
{
return X;
}
nathan@uha:277>./cc1plus -fpreprocessed cpp.ii -quiet
2.95 says
nathan@uha:278>g++ -save-temps current/cpp.C -c
current/cpp.C:3: undefined or invalid # directive
current/cpp.C: In function `const char * foo()':
current/cpp.C:7: `X' undeclared (first use this function)
current/cpp.C:7: (Each undeclared identifier is reported only once
current/cpp.C:7: for each function it appears in.)
current/cpp.C:8: warning: control reaches end of non-void function `foo()'
nathan@uha:279>more cpp.ii
# 1 "current/cpp.C"
# define X "string"
# include "thing"
char const *foo ()
{
return X;
}
nathan@uha:280>g++ cpp.ii -c
current/cpp.C:3: undefined or invalid # directive
current/cpp.C: In function `const char * foo()':
current/cpp.C:7: `X' undeclared (first use this function)
current/cpp.C:7: (Each undeclared identifier is reported only once
current/cpp.C:7: for each function it appears in.)
current/cpp.C:8: warning: control reaches end of non-void function `foo()'
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="cpp.C"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="cpp.C"
I2RlZmluZSBIQVNIICMKSEFTSCBkZWZpbmUgWCAic3RyaW5nIgpIQVNIIGluY2x1ZGUgInRoaW5n
IgoKY2hhciBjb25zdCAqZm9vICgpCnsKICAgIHJldHVybiBYOwp9Cg==