[Bug preprocessor/17206] New: Preprocessor mishandles #ident directive

sobomax at freebsd dot org gcc-bugzilla@gcc.gnu.org
Fri Aug 27 06:19:00 GMT 2004


When doing only preprocessing (flag -E), preprocessor puts extra quotes ("") 
around argument of #ident directive, resulting in "extra tokens at end of 
#ident directive" compiler warning or error, if treat warnings as errors option 
is enabled. Following script illustrates the problem:

-bash-2.05b$ echo '#ident "foo bar"' > /tmp/foo.c
-bash-2.05b$ cc -E /tmp/foo.c
# 1 "/tmp/foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "/tmp/foo.c"
#ident ""foo bar""
-bash-2.05b$ cc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.2 [FreeBSD] 20040728
-bash-2.05b$

This bug doesn't hit when doing full compilation, since in this case no 
inermediate preprocessed output is emitted. It affects compilation with ccache, 
since ccache does cc -E first and then invokes compiler on the preprocessor 
output. Following small patch fixes the problem.

--- src/contrib/gcc/c-ppoutput.c	2004/08/26 14:10:04	1.1
+++ src/contrib/gcc/c-ppoutput.c	2004/08/26 14:10:32
@@ -292,7 +292,7 @@
 	  const cpp_string *str)
 {
   maybe_print_line (print.map, line);
-  fprintf (print.outf, "#ident \"%s\"\n", str->text);
+  fprintf (print.outf, "#ident %s\n", str->text);
   print.line++;
 }

-- 
           Summary: Preprocessor mishandles #ident directive
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sobomax at freebsd dot org
                CC: gcc-bugs at gcc dot gnu dot org,kan at FreeBSD dot ORG


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17206



More information about the Gcc-bugs mailing list