preprocessor: Support C2X #elifdef, #elifndef
authorJoseph Myers <joseph@codesourcery.com>
Tue, 11 May 2021 23:54:01 +0000 (23:54 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Tue, 11 May 2021 23:54:01 +0000 (23:54 +0000)
commit71d38ec80008afdbb9a059253407d80598b765c0
tree61d4686bb430d8369941427a4d05c34522007f48
parent415bcabf134b90794a134ca5dadfaf44496645d5
preprocessor: Support C2X #elifdef, #elifndef

C2X adds #elifdef and #elifndef preprocessor directives; these have
also been proposed for C++.  Implement these directives in libcpp
accordingly.

In this implementation, #elifdef and #elifndef are treated as
non-directives for any language version other than c2x and gnu2x (if
the feature is accepted for C++, it can trivially be enabled for
relevant C++ versions).  In strict conformance modes for prior
language versions, this is required, as illustrated by the
c11-elifdef-1.c test added.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

libcpp/
* include/cpplib.h (struct cpp_options): Add elifdef.
* init.c (struct lang_flags): Add elifdef.
(lang_defaults): Update to include elifdef initializers.
(cpp_set_lang): Set elifdef for pfile based on language.
* directives.c (STDC2X, ELIFDEF): New macros.
(EXTENSION): Increase value to 3.
(DIRECTIVE_TABLE): Add #elifdef and #elifndef.
(_cpp_handle_directive): Do not treat ELIFDEF directives as
directives for language versions without the #elifdef feature.
(do_elif): Handle #elifdef and #elifndef.
(do_elifdef, do_elifndef): New functions.

gcc/testsuite/
* gcc.dg/cpp/c11-elifdef-1.c, gcc.dg/cpp/c2x-elifdef-1.c,
gcc.dg/cpp/c2x-elifdef-2.c: New tests.
gcc/testsuite/gcc.dg/cpp/c11-elifdef-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/c2x-elifdef-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/c2x-elifdef-2.c [new file with mode: 0644]
libcpp/directives.c
libcpp/include/cpplib.h
libcpp/init.c