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.
This commit is contained in:
parent
415bcabf13
commit
71d38ec800
6 changed files with 224 additions and 35 deletions
|
@ -497,6 +497,9 @@ struct cpp_options
|
|||
/* Nonzero for the '::' token. */
|
||||
unsigned char scope;
|
||||
|
||||
/* Nonzero for the '#elifdef' and '#elifndef' directives. */
|
||||
unsigned char elifdef;
|
||||
|
||||
/* Nonzero means tokenize C++20 module directives. */
|
||||
unsigned char module_directives;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue