From 894356fd0db241d5424c6beae9a12075ed81ad6b Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 8 Jul 2016 09:21:13 -0400 Subject: [PATCH 15/38] FIXME: WIP improvements to wrong-arg-count for macros --- gcc/testsuite/gcc.dg/cpp/macro-wrong-num-args.c | 14 ++++++++++++++ libcpp/macro.c | 13 ++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/macro-wrong-num-args.c diff --git a/gcc/testsuite/gcc.dg/cpp/macro-wrong-num-args.c b/gcc/testsuite/gcc.dg/cpp/macro-wrong-num-args.c new file mode 100644 index 0000000..5a3da9e --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/macro-wrong-num-args.c @@ -0,0 +1,14 @@ +/* Verify that we print the location of the macro definition when + handling bad macro argument counts. */ + +#define MACRO_A(X, Y, Z) /* { dg-message "0: macro \"MACRO_A\" defined here" } */ + +#define MACRO_B(X) /* { dg-message "0: macro \"MACRO_B\" defined here" } */ + +/* Not enough args. */ +MACRO_A(42) /* { dg-error "macro \"MACRO_A\" requires 3 arguments, but only 1 given" } */ + +/* Too many args. */ +MACRO_B(1, 2, 3) /* dg-error "macro \"MACRO_B\" passed 3 arguments, but takes just 1" } */ + +int nonempty; diff --git a/libcpp/macro.c b/libcpp/macro.c index 147fcf5..1e3803a 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -795,11 +795,18 @@ _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node cpp_error (pfile, CPP_DL_ERROR, "macro \"%s\" requires %u arguments, but only %u given", NODE_NAME (node), macro->paramc, argc); + + cpp_error_at (pfile, CPP_DL_NOTE, macro->line, + "macro \"%s\" defined here", NODE_NAME (node)); } else - cpp_error (pfile, CPP_DL_ERROR, - "macro \"%s\" passed %u arguments, but takes just %u", - NODE_NAME (node), argc, macro->paramc); + { + cpp_error (pfile, CPP_DL_ERROR, + "macro \"%s\" passed %u arguments, but takes just %u", + NODE_NAME (node), argc, macro->paramc); + cpp_error_at (pfile, CPP_DL_NOTE, macro->line, + "macro \"%s\" defined here", NODE_NAME (node)); + } return false; } -- 1.8.5.3