libcpp: show macro definition when used with wrong argument count
commit5a60b5b74a617e4f7a84755df95c86289dda4d0d
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 11 Oct 2018 13:21:28 +0000 (11 13:21 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 11 Oct 2018 13:21:28 +0000 (11 13:21 +0000)
treedec8d87521395a312aab96b828e7959479b364f8
parent04daf5ec28a306132902290b2a43f7de1fabcdc6
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: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265040 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/cpp/macro-arg-count-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/cpp/macro-arg-count-2.c [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/macro-arg-count.C [deleted file]
libcpp/ChangeLog
libcpp/macro.c