diff --git a/gcc/testsuite/gcc.dg/cpp/pr101638.c b/gcc/testsuite/gcc.dg/cpp/pr101638.c new file mode 100644 index 00000000000..103047320d0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr101638.c @@ -0,0 +1,7 @@ +/* PR preprocessor/101638 */ +/* { dg-do preprocess } */ +/* { dg-options "-Wtraditional" } */ + +#define foo(attr) __has_attribute(attr) +#if foo(__deprecated__) +#endif diff --git a/libcpp/macro.c b/libcpp/macro.c index 4fc5f838919..fab6779ef89 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -3116,7 +3116,8 @@ cpp_get_token_with_location (cpp_reader *pfile, location_t *loc) /* Returns true if we're expanding an object-like macro that was defined in a system header. Just checks the macro at the top of - the stack. Used for diagnostic suppression. */ + the stack. Used for diagnostic suppression. + Also return true for builtin macros. */ int cpp_sys_macro_p (cpp_reader *pfile) { @@ -3127,7 +3128,11 @@ cpp_sys_macro_p (cpp_reader *pfile) else node = pfile->context->c.macro; - return node && node->value.macro && node->value.macro->syshdr; + if (!node) + return false; + if (cpp_builtin_macro_p (node)) + return true; + return node->value.macro && node->value.macro->syshdr; } /* Read each token in, until end of the current file. Directives are