gcc/libcpp
Nathan Sidwell ad1a3914ae [PR 80005] Fix __has_include
__has_include is funky in that it is macro-like from the POV of #ifdef and
friends, but lexes its parenthesize argument #include-like.  We were
failing the second part of that, because we used a forwarding macro to an
internal name, and hence always lexed the argument in macro-parameter
context.  We componded that by not setting the right flag when lexing, so
it didn't even know.  Mostly users got lucky.

This reimplements the handline.
1) Remove the forwarding, but declare object-like macros that
expand to themselves.  This satisfies the #ifdef requirement

2) Correctly set angled_brackets when lexing the parameter.  This tells
the lexer (a) <...> is a header name and (b) "..." is too (not a string).

3) Remove the in__has_include lexer state, just tell find_file that that's
what's happenning, so it doesn't emit an error.

We lose the (undocumented) ability to #undef __has_include.  That may well
have been an accident of implementation.  There are no tests for it.

We gain __has_include behaviour for all users of the preprocessors -- not
just the C-family ones that defined a forwarding macro.

	libcpp/
	PR preprocessor/80005
	* include/cpplib.h (BT_HAS_ATTRIBUTE): Fix comment.
	* internal.h (struct lexer_state): Delete in__has_include field.
	(struct spec_nodes): Rename n__has_include{,_next}__ fields.
	(_cpp_defined_macro_p): New.
	(_cpp_find_file): Add has_include parm.
	* directives.c (lex_macro_node): Combine defined,
	__has_inline{,_next} checking.
	(do_ifdef, do_ifndef): Use _cpp_defined_macro_p.
	(_cpp_init_directives): Refactor.
	* expr.c (parse_defined): Use _cpp_defined_macro_p.
	(eval_token): Adjust parse_has_include calls.
	(parse_has_include): Add OP parameter.  Reimplement.
	* files.c (_cpp_find_file): Add HAS_INCLUDE parm.  Use it to
	inhibit error message.
	(_cpp_stack_include): Adjust _cpp_find_file call.
	(_cpp_fake_include, _cpp_compare_file_date): Likewise.
	(open_file_failed): Remove in__has_include check.
	(_cpp_has_header): Adjust _cpp_find_file call.
	* identifiers.c (_cpp_init_hashtable): Don't init
	__has_include{,_next} here ...
	* init.c (cpp_init_builtins): ... init them here.  Define as
	macros.
	(cpp_read_main_file): Adjust _cpp_find_file call.
	* pch.c (cpp_read_state): Adjust __has_include{,_next} access.
	* traditional.c (_cpp_scan_out_locgical_line): Likewise.

	gcc/c-family/
	PR preprocessor/80005
	* c-cppbuiltins.c (c_cpp_builtins): Don't define __has_include{,_next}.

	gcc/testsuite/
	PR preprocessor/80005
	* g++.dg/cpp1y/feat-cxx14.C: Adjust.
	* g++.dg/cpp1z/feat-cxx17.C: Adjust.
	* g++.dg/cpp2a/feat-cxx2a.C: Adjust.
	* g++.dg/cpp/pr80005.C: New.
2020-01-20 05:39:59 -08:00
..
include [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
po * zh_TW.po: Update. 2019-08-09 23:02:08 +01:00
ChangeLog [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
ChangeLog.jit
Makefile.in Update copyright years. 2020-01-01 12:51:42 +01:00
aclocal.m4
charset.c Update copyright years. 2020-01-01 12:51:42 +01:00
config.in
configure iconv.m4 (AM_ICONV_LINK): Don't overwrite CPPFLAGS. 2018-11-07 15:41:21 -07:00
configure.ac
directives-only.c Update copyright years. 2020-01-01 12:51:42 +01:00
directives.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
errors.c Update copyright years. 2020-01-01 12:51:42 +01:00
expr.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
files.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
generated_cpp_wcwidth.h Byte vs column awareness for diagnostic-show-locus.c (PR 49973) 2019-12-09 20:03:47 +00:00
identifiers.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
init.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
internal.h [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
lex.c Update copyright years. 2020-01-01 12:51:42 +01:00
line-map.c Add diagnostic paths 2020-01-10 21:22:12 +00:00
location-example.txt PR preprocessor/83173: Enhance -fdump-internal-locations output 2018-11-27 16:04:31 +00:00
macro.c Update copyright years. 2020-01-01 12:51:42 +01:00
makeucnid.c Update copyright years. 2020-01-01 12:51:42 +01:00
mkdeps.c Work around array out of bounds warning in mkdeps 2020-01-16 11:09:24 +01:00
pch.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
symtab.c Update copyright years. 2020-01-01 12:51:42 +01:00
system.h Update copyright years. 2020-01-01 12:51:42 +01:00
traditional.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
ucnid.h Update copyright years. 2020-01-01 12:51:42 +01:00
ucnid.tab Update copyright years. 2020-01-01 12:51:42 +01:00