]> git.ipfire.org Git - thirdparty/gcc.git/commit
C/C++: Better notification if misused a function like macro [PR102846]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 15 Oct 2025 00:50:13 +0000 (17:50 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 28 Jan 2026 18:20:38 +0000 (10:20 -0800)
commit00956e55dd2fbbee751e953ca2f6b8a87151f85b
tree55351c7bae1c2fa8fa31c318ba332e576d54e476
parentbaaa412ae73c12e2e5ea2552534ec42525f6d21e
C/C++: Better notification if misused a function like macro [PR102846]

Currently if assert is misused, e.g. like passing to a function like a
function pointer, GCC suggests to include assert.h/cassert. But since
it is already included that is just a bogus suggestion. Instead we should
see if a function-like macro is that same name (in the case of assert it will be),
and inform the user that it is being mis-used.

PR c++/102846
PR c/102846

gcc/c-family/ChangeLog:

* known-headers.cc (macro_like_function_used::macro_like_function_used): New.
(macro_like_function_used::~macro_like_function_used): New.
* known-headers.h (class macro_like_function_used): New class.

gcc/c/ChangeLog:

* c-decl.cc (lookup_name_fuzzy): Lookup function-like macro and
notify of misuse there.

gcc/cp/ChangeLog:

* name-lookup.cc (lookup_name_fuzzy): Lookup function-like macro and
notify of misuse there.

gcc/testsuite/ChangeLog:

* c-c++-common/function-like-macro-1.c: New test.
* c-c++-common/function-like-macro-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/c-family/known-headers.cc
gcc/c-family/known-headers.h
gcc/c/c-decl.cc
gcc/cp/name-lookup.cc
gcc/testsuite/c-c++-common/function-like-macro-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/function-like-macro-2.c [new file with mode: 0644]