aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-10-11 13:21:28 +0000
committerDavid Malcolm <dmalcolm@redhat.com>2018-10-11 13:21:28 +0000
commite1f5e0d5c92fd3e49edf63927a82d2cafa9a57b8 (patch)
treedec8d87521395a312aab96b828e7959479b364f8 /libcpp
parent3197182c4d8c71261d1bc2added4862403bdac11 (diff)
libcpp: show macro definition when used with wrong argument count
Consider: demo.c: In function 'test': demo.c:5:40: error: macro "LOG_2" requires 3 arguments, but only 2 given 5 | LOG_2 ("loading file: %s\n", filename); | ^ This patch adds a note showing the definition of the macro in question, giving: demo.c: In function 'test': demo.c:5:40: error: macro "LOG_2" requires 3 arguments, but only 2 given 5 | LOG_2 ("loading file: %s\n", filename); | ^ In file included from demo.c:1: logging.h:1: note: macro "LOG_2" defined here 1 | #define LOG_2(FMT, ARG0, ARG1) do { fprintf (stderr, (FMT), (ARG0), (ARG1)); } | gcc/testsuite/ChangeLog: * g++.dg/diagnostic/macro-arg-count.C: Move to... * c-c++-common/cpp/macro-arg-count-1.c: ...here, generalizing output for C vs C++. Expect notes showing the definitions of the macros. * c-c++-common/cpp/macro-arg-count-2.c: New test, adapted from the above. libcpp/ChangeLog: * macro.c (_cpp_arguments_ok): If the argument count is wrong, add a note showing the definition of the macro. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@265040 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog5
-rw-r--r--libcpp/macro.c4
2 files changed, 9 insertions, 0 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index fe0dc8ddfe5..e240b2c7058 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-11 David Malcolm <dmalcolm@redhat.com>
+
+ * macro.c (_cpp_arguments_ok): If the argument count is wrong, add
+ a note showing the definition of the macro.
+
2018-10-11 Nathan Sidwell <nathan@acm.org>
* include/line-map.h (LINEMAPS_MACRO_LOWEST_LOCATION): Fix
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 073816dd221..aacaf8c3020 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -964,6 +964,10 @@ _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node
"macro \"%s\" passed %u arguments, but takes just %u",
NODE_NAME (node), argc, macro->paramc);
+ if (macro->line > RESERVED_LOCATION_COUNT)
+ cpp_error_at (pfile, CPP_DL_NOTE, macro->line, "macro \"%s\" defined here",
+ NODE_NAME (node));
+
return false;
}