]> gcc.gnu.org Git - gcc.git/commit
libcpp: Fix macro expansion for argument of __has_include [PR110558]
authorLewis Hyatt <lhyatt@gmail.com>
Tue, 12 Dec 2023 22:46:36 +0000 (17:46 -0500)
committerLewis Hyatt <lhyatt@gmail.com>
Thu, 14 Mar 2024 11:33:02 +0000 (07:33 -0400)
commit942497ad74272e0ef16020d628e471c5f21474b0
tree4eeaf9038cc0ecf82b504ab914d16082fe5d8e7f
parent6c166e55b15894ceb07dcc7b55f900e50e24ec5b
libcpp: Fix macro expansion for argument of __has_include [PR110558]

When the file name for a #include directive is the result of stringifying a
macro argument, libcpp needs to take some care to get the whitespace
correct; in particular stringify_arg() needs to see a CPP_PADDING token
between macro tokens so that it can figure out when to output space between
tokens. The CPP_PADDING tokens are not normally generated when handling a
preprocessor directive, but for #include-like directives, libcpp sets the
state variable pfile->state.directive_wants_padding to TRUE so that the
CPP_PADDING tokens will be output, and then everything works fine for
computed includes.

As the PR points out, things do not work fine for __has_include. Fix that by
setting the state variable the same as is done for #include.

libcpp/ChangeLog:

PR preprocessor/110558
* macro.cc (builtin_has_include): Set
pfile->state.directive_wants_padding prior to lexing the
file name, in case it comes from macro expansion.

gcc/testsuite/ChangeLog:

PR preprocessor/110558
* c-c++-common/cpp/has-include-2.c: New test.
* c-c++-common/cpp/has-include-2.h: New test.
gcc/testsuite/c-c++-common/cpp/has-include-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/cpp/has-include-2.h [new file with mode: 0644]
libcpp/macro.cc
This page took 0.065189 seconds and 5 git commands to generate.