b/gcc/testsuite/c-c++-common/cpp/diagnostic-pragma-1.c
@@ -9,3 +9,6 @@
char a[CONST1]; // { dg-warning warn-c }
char b[CONST2]; // { dg-error err-d }
+#define EXPAND "exp-"
+#pragma GCC warning "warn-" EXPAND "e" // { dg-warning warn-exp-e }
+#pragma GCC error "err-" EXPAND "f" // { dg-error err-exp-f }
@@ -1740,19 +1740,49 @@ do_pragma_dependency (cpp_reader *pfile)
static void
do_pragma_warning_or_error (cpp_reader *pfile, bool error)
{
- const cpp_token *tok = _cpp_lex_token (pfile);
+ size_t count = 0;
+ obstack str_ob;
+ obstack_specify_allocation (&str_ob, 0, 0, xmalloc, free);
+ location_t loc;
+ location_t loc_end;
+ gcc_assert (pfile->state.prevent_expansion > 0);
+ pfile->state.prevent_expansion--;
+ for (;; ++count)
+ {
+ const cpp_token *tok = cpp_get_token (pfile);
+ if (tok->type != CPP_STRING)
+ break;
+ if (count == 0)
+ loc = tok->src_loc;
+ obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string));
+ loc_end = tok->src_loc;
+ }
+ pfile->state.prevent_expansion++;
+ if (count == 0)
+ {
+ cpp_error (pfile, CPP_DL_ERROR, "invalid \"#pragma GCC %s\"
directive",
+ error ? "error" : "warning");
+ return;
+ }
+ cpp_string * strs = (cpp_string *) obstack_finish (&str_ob);
cpp_string str;
- if (tok->type != CPP_STRING
- || !cpp_interpret_string_notranslate (pfile, &tok->val.str, 1, &str,
- CPP_STRING)
- || str.len == 0)
+ bool combine = cpp_interpret_string_notranslate (pfile, strs, count,
+ &str, CPP_STRING);
+ obstack_free (&str_ob, 0);
+ if (!combine || str.len == 0)
{
cpp_error (pfile, CPP_DL_ERROR, "invalid \"#pragma GCC %s\"
directive",
error ? "error" : "warning");
return;
}
- cpp_error (pfile, error ? CPP_DL_ERROR : CPP_DL_WARNING,
- "%s", str.text);
+ if (count != 1)
+ {
+ //TODO: combine loc, loc_end into
+ // loc = COMBINE_LOCATION_DATA (pfile->line_table, ..., ..., NULL);
+ (void)loc_end;
+ }
+ cpp_error_at (pfile, error ? CPP_DL_ERROR : CPP_DL_WARNING, loc,
+ "%s", str.text);
free ((void *)str.text);