https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66317
Bug ID: 66317 Summary: Preprocessor chokes on __FILE__ containing a newline Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: Keith.S.Thompson at gmail dot com Target Milestone: --- This is an obscure problem, unlikely to occur in the real world. I do not suggest handling it "correctly", whatever that might mean, just detecting it and terminating with a reasonable error message. The problem can also occur if the actual file name contains a newline. System: Linux Mint 17. gcc version 5.1.0, built from source with: gcc-5.1.0/configure --prefix=/usr/local/apps/gcc-5.1.0 --disable-multilib Test case (a 2 line source file named "filename_bug.c"): #line 1 "new\nline.c" const char filename[] = __FILE__; Output of "cpp filename_bug.c" (there is no newline on the last line of output): # 1 "filename_bug.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "filename_bug.c" # 1 "new line.c" new line.c:1:1: warning: missing terminating " character new line.c:1:25: internal compiler error: invalid built-in macro "__FILE__" 0x6449a8 c_cpp_error(cpp_reader*, int, int, unsigned int, unsigned int, char const*, __va_list_tag (*) [1]) ../gcc-5.1.0/gcc/c-family/c-common.c:10029 0xf6664a cpp_diagnostic ../gcc-5.1.0/libcpp/errors.c:60 0xf66776 cpp_error(cpp_reader*, int, char const*, ...) ../gcc-5.1.0/libcpp/errors.c:75 0xf74158 builtin_macro ../gcc-5.1.0/libcpp/macro.c:471 0xf748ed enter_macro_context ../gcc-5.1.0/libcpp/macro.c:1247 0xf7643d cpp_get_token_1 ../gcc-5.1.0/libcpp/macro.c:2526 0x65830f scan_translation_unit ../gcc-5.1.0/gcc/c-family/c-ppoutput.c:192 0x65830f preprocess_file(cpp_reader*) ../gcc-5.1.0/gcc/c-family/c-ppoutput.c:113 0x656c80 c_common_init() ../gcc-5.1.0/gcc/c-family/c-opts.c:1033 0x5cb33e lang_dependent_init ../gcc-5.1.0/gcc/toplev.c:1845 0x5cb33e do_compile ../gcc-5.1.0/gcc/toplev.c:2062 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. const char filename[] =