" this is probably fixable by adding %qs to the command-line options",
m_name_str, option_name, option_name);
}
+
+/* macro_like_function_used's ctor. */
+
+macro_like_function_used::macro_like_function_used (location_t loc, const char *name)
+: deferred_diagnostic (loc), m_name_str (name)
+{
+ gcc_assert (name);
+}
+
+/* macro_like_function_used's dtor. */
+
+macro_like_function_used::~macro_like_function_used ()
+{
+ if (is_suppressed_p ())
+ return;
+
+ inform (get_location (),
+ "%qs is a function-like macro and might be used incorrectly",
+ m_name_str);
+}
diagnostics::option_id m_option_id;
};
+/* Subclass of deferred_diagnostic for suggesting to the user
+ that they have misused a function like macro. */
+class macro_like_function_used : public deferred_diagnostic
+{
+ public:
+ macro_like_function_used (location_t loc, const char *name);
+
+ ~macro_like_function_used ();
+
+ private:
+ const char *m_name_str;
+};
+
#endif /* GCC_KNOWN_HEADERS_H */
{
gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
- /* First, try some well-known names in the C standard library, in case
+ /* Look up function-like macros first; maybe misusing them. */
+ auto cpp_node = cpp_lookup (parse_in,
+ (const unsigned char*)IDENTIFIER_POINTER (name),
+ IDENTIFIER_LENGTH (name));
+ if (cpp_node && cpp_fun_like_macro_p (cpp_node))
+ return name_hint
+ (nullptr,
+ std::make_unique<macro_like_function_used> (loc,
+ IDENTIFIER_POINTER (name)));
+
+ /* Next, try some well-known names in the C standard library, in case
the user forgot a #include. */
const char *header_hint
= get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name));
{
gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
- /* First, try some well-known names in the C++ standard library, in case
+ /* Look up function-like macros first; maybe misusing them. */
+ auto cpp_node = cpp_lookup (parse_in,
+ (const unsigned char*)IDENTIFIER_POINTER (name),
+ IDENTIFIER_LENGTH (name));
+ if (cpp_node && cpp_fun_like_macro_p (cpp_node))
+ return name_hint
+ (nullptr,
+ std::make_unique<macro_like_function_used> (loc,
+ IDENTIFIER_POINTER (name)));
+
+ /* Then, try some well-known names in the C++ standard library, in case
the user forgot a #include. */
const char *header_hint
= get_cp_stdlib_header_for_name (IDENTIFIER_POINTER (name));
--- /dev/null
+/* { dg-do compile } */
+/* PR c/102846 */
+
+#define f(a) ((void)0)
+
+void g(int a)
+{
+ (f)(a); /* { dg-error "was not declared|undeclared" "undeclared" } */
+ /* { dg-message "is a function-like macro and might be used incorrectly" "" { target *-*-* } .-1 } */
+}
--- /dev/null
+/* { dg-do compile } */
+/* PR c/102846 */
+
+#include <assert.h>
+
+void g(int a)
+{
+ (assert)(a); /* { dg-error "was not declared|undeclared" "undeclared" } */
+ /* { dg-message "is a function-like macro and might be used incorrectly" "macro" { target *-*-* } .-1 } */
+ /* { dg-bogus "is defined in header" "header" { target *-*-* } .-2 }*/
+}