diff options
author | Nathan Sidwell <nathan@acm.org> | 2020-01-28 07:58:29 -0800 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2020-01-28 08:02:17 -0800 |
commit | 3d056cbfb3484f4037b34c908b26e1c6776c86b5 (patch) | |
tree | 591410d4cd98b8777276072cc5af998a3f97d97c /libcpp/init.c | |
parent | a5d81aaab6d54379cd3835b33d84d9be5c5be099 (diff) | |
download | gcc-3d056cbfb3484f4037b34c908b26e1c6776c86b5.tar.gz |
preprocessor: Make __has_include a builtin macro [PR93452]
The clever hack of '#define __has_include __has_include' breaks -dD
and -fdirectives-only, because that emits definitions. This turns
__has_include into a proper builtin macro. Thus it's never emitted
via -dD, and because use outside of directive processing is undefined,
we can just expand it anywhere.
PR preprocessor/93452
* internal.h (struct spec_nodes): Drop n__has_include{,_next}.
* directives.c (lex_macro_node): Don't check __has_include redef.
* expr.c (eval_token): Drop __has_include eval.
(parse_has_include): Move to ...
* macro.c (builtin_has_include): ... here.
(_cpp_builtin_macro_text): Eval __has_include{,_next}.
* include/cpplib.h (enum cpp_builtin_type): Add BT_HAS_INCLUDE{,_NEXT}.
* init.c (builtin_array): Add them.
(cpp_init_builtins): Drop __has_include{,_next} init here ...
* pch.c (cpp_read_state): ... and here.
* traditional.c (enum ls): Drop has_include states ...
(_cpp_scan_out_logical_line): ... and here.
Diffstat (limited to 'libcpp/init.c')
-rw-r--r-- | libcpp/init.c | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/libcpp/init.c b/libcpp/init.c index e798140ef8b..a3cd8e28f62 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -404,6 +404,8 @@ static const struct builtin_macro builtin_array[] = B("__has_attribute", BT_HAS_ATTRIBUTE, true), B("__has_cpp_attribute", BT_HAS_ATTRIBUTE, true), B("__has_builtin", BT_HAS_BUILTIN, true), + B("__has_include", BT_HAS_INCLUDE, true), + B("__has_include_next",BT_HAS_INCLUDE_NEXT, true), /* Keep builtins not used for -traditional-cpp at the end, and update init_builtins() if any more are added. */ B("_Pragma", BT_PRAGMA, true), @@ -578,17 +580,6 @@ cpp_init_builtins (cpp_reader *pfile, int hosted) if (CPP_OPTION (pfile, objc)) _cpp_define_builtin (pfile, "__OBJC__ 1"); - - /* These two behave as macros for #ifdef, but are evaluated - specially inside #if. */ - _cpp_define_builtin (pfile, "__has_include __has_include"); - _cpp_define_builtin (pfile, "__has_include_next __has_include_next"); - pfile->spec_nodes.n__has_include - = cpp_lookup (pfile, DSC("__has_include")); - pfile->spec_nodes.n__has_include->flags |= NODE_DIAGNOSTIC; - pfile->spec_nodes.n__has_include_next - = cpp_lookup (pfile, DSC("__has_include_next")); - pfile->spec_nodes.n__has_include_next->flags |= NODE_DIAGNOSTIC; } /* Sanity-checks are dependent on command-line options, so it is |