Index: gcc/testsuite/gcc.dg/cpp/empty-include.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/empty-include.c (revision 148683) +++ gcc/testsuite/gcc.dg/cpp/empty-include.c (working copy) @@ -7,7 +7,8 @@ * * We should get an error. */ /* { dg-do preprocess } */ -#include "" /* { dg-error "empty" "error on empty filename in include" } */ +/* { dg-options "-fshow-column" } */ +#include "" /* { dg-error "10:empty" "error on empty filename in include" } */ int x; /* Otherwise we have an empty file and get more errors. */ Index: gcc/testsuite/gcc.dg/cpp/assert2.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/assert2.c (revision 148683) +++ gcc/testsuite/gcc.dg/cpp/assert2.c (working copy) @@ -1,24 +1,24 @@ /* Malformed assertion tests. */ /* { dg-do preprocess } */ -/* { dg-options "-Wno-deprecated" } */ +/* { dg-options "-fshow-column -Wno-deprecated" } */ #assert /* { dg-error "without predicate" "assert w/o predicate" } */ -#assert % /* { dg-error "an identifier" "assert punctuation" } */ -#assert 12 /* { dg-error "an identifier" "assert number" } */ -#assert abc /* { dg-error "missing" "assert w/o answer" } */ +#assert % /* { dg-error "9:an identifier" "assert punctuation" } */ +#assert 12 /* { dg-error "9:an identifier" "assert number" } */ +#assert abc /* { dg-error "9:missing" "assert w/o answer" } */ #if # /* { dg-error "without predicate" "test w/o predicate" } */ #endif -#if #% /* { dg-error "an identifier" "test punctuation" } */ +#if #% /* { dg-error "6:an identifier" "test punctuation" } */ #endif -#if #12 /* { dg-error "an identifier" "test number" } */ +#if #12 /* { dg-error "6:an identifier" "test number" } */ #endif #if #abc #error /* { dg-bogus "error" "test w/o answer" } */ #endif -#if #abc[def] /* { dg-error "is not valid" "test with malformed answer" } */ +#if #abc[def] /* { dg-error "9:is not valid" "test with malformed answer" } */ #endif Index: libcpp/directives.c =================================================================== --- libcpp/directives.c (revision 148683) +++ libcpp/directives.c (working copy) @@ -97,11 +97,12 @@ static void start_directive (cpp_reader static void prepare_directive_trad (cpp_reader *); static void end_directive (cpp_reader *, int); static void directive_diagnostics (cpp_reader *, const directive *, int); static void run_directive (cpp_reader *, int, const char *, size_t); static char *glue_header_name (cpp_reader *); -static const char *parse_include (cpp_reader *, int *, const cpp_token ***); +static const char *parse_include (cpp_reader *, int *, const cpp_token ***, + source_location *); static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *); static unsigned int read_flag (cpp_reader *, unsigned int); static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *); static void do_diagnostic (cpp_reader *, int, int); static cpp_hashnode *lex_macro_node (cpp_reader *, bool); @@ -119,11 +120,11 @@ static void do_pragma_system_header (cpp static void do_pragma_dependency (cpp_reader *); static void do_linemarker (cpp_reader *); static const cpp_token *get_token_no_padding (cpp_reader *); static const cpp_token *get__Pragma_string (cpp_reader *); static void destringize_and_run (cpp_reader *, const cpp_string *); -static int parse_answer (cpp_reader *, struct answer **, int); +static int parse_answer (cpp_reader *, struct answer **, int, source_location); static cpp_hashnode *parse_assertion (cpp_reader *, struct answer **, int); static struct answer ** find_answer (cpp_hashnode *, const struct answer *); static void handle_assertion (cpp_reader *, const char *, int); /* This is the table of directive handlers. It is ordered by @@ -681,20 +682,23 @@ glue_header_name (cpp_reader *pfile) return buffer; } /* Returns the file name of #include, #include_next, #import and #pragma dependency. The string is malloced and the caller should - free it. Returns NULL on error. */ + free it. Returns NULL on error. LOCATION is the source location + of the file name. */ + static const char * parse_include (cpp_reader *pfile, int *pangle_brackets, - const cpp_token ***buf) + const cpp_token ***buf, source_location *location) { char *fname; const cpp_token *header; /* Allow macro expansion. */ header = get_token_no_padding (pfile); + *location = header->src_loc; if (header->type == CPP_STRING || header->type == CPP_HEADER_NAME) { fname = XNEWVEC (char, header->val.str.len - 1); memcpy (fname, header->val.str.text + 1, header->val.str.len - 2); fname[header->val.str.len - 2] = '\0'; @@ -740,27 +744,29 @@ static void do_include_common (cpp_reader *pfile, enum include_type type) { const char *fname; int angle_brackets; const cpp_token **buf = NULL; + source_location location; /* Re-enable saving of comments if requested, so that the include callback can dump comments which follow #include. */ pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); - fname = parse_include (pfile, &angle_brackets, &buf); + fname = parse_include (pfile, &angle_brackets, &buf, &location); if (!fname) { if (buf) XDELETEVEC (buf); return; } if (!*fname) { - cpp_error (pfile, CPP_DL_ERROR, "empty filename in #%s", - pfile->directive->name); + cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0, + "empty filename in #%s", + pfile->directive->name); XDELETEVEC (fname); if (buf) XDELETEVEC (buf); return; } @@ -1476,12 +1482,13 @@ do_pragma_system_header (cpp_reader *pfi static void do_pragma_dependency (cpp_reader *pfile) { const char *fname; int angle_brackets, ordering; + source_location location; - fname = parse_include (pfile, &angle_brackets, NULL); + fname = parse_include (pfile, &angle_brackets, NULL, &location); if (!fname) return; ordering = _cpp_compare_file_date (pfile, fname, angle_brackets); if (ordering < 0) @@ -1898,13 +1905,15 @@ push_conditional (cpp_reader *pfile, int } /* Read the tokens of the answer into the macro pool, in a directive of type TYPE. Only commit the memory if we intend it as permanent storage, i.e. the #assert case. Returns 0 on success, and sets - ANSWERP to point to the answer. */ + ANSWERP to point to the answer. PRED_LOC is the location of the + predicate. */ static int -parse_answer (cpp_reader *pfile, struct answer **answerp, int type) +parse_answer (cpp_reader *pfile, struct answer **answerp, int type, + source_location pred_loc) { const cpp_token *paren; struct answer *answer; unsigned int acount; @@ -1925,11 +1934,12 @@ parse_answer (cpp_reader *pfile, struct /* #unassert with no answer is valid - it removes all answers. */ if (type == T_UNASSERT && paren->type == CPP_EOF) return 0; - cpp_error (pfile, CPP_DL_ERROR, "missing '(' after predicate"); + cpp_error_with_line (pfile, CPP_DL_ERROR, pred_loc, 0, + "missing '(' after predicate"); return 1; } for (acount = 0;; acount++) { @@ -1989,12 +1999,13 @@ parse_assertion (cpp_reader *pfile, stru *answerp = 0; predicate = cpp_get_token (pfile); if (predicate->type == CPP_EOF) cpp_error (pfile, CPP_DL_ERROR, "assertion without predicate"); else if (predicate->type != CPP_NAME) - cpp_error (pfile, CPP_DL_ERROR, "predicate must be an identifier"); - else if (parse_answer (pfile, answerp, type) == 0) + cpp_error_with_line (pfile, CPP_DL_ERROR, predicate->src_loc, 0, + "predicate must be an identifier"); + else if (parse_answer (pfile, answerp, type, predicate->src_loc) == 0) { unsigned int len = NODE_LEN (predicate->val.node.node); unsigned char *sym = (unsigned char *) alloca (len + 1); /* Prefix '#' to get it out of macro namespace. */