Skip to content

Commit

Permalink
C++23 preprocessor extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
guwirth committed Aug 28, 2024
1 parent 41ab59e commit 9cb98e6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ void warningLine() {
p.setRootRule(g.rule(PPGrammarImpl.warningLine));

assertThat(p).matches("#warning foo");
assertThat(p).matches("#warning");
}

@Test
Expand Down
48 changes: 48 additions & 0 deletions cxx-squid/src/test/resources/parser/own/C++23/elifxdef.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
void sample() {

// Note that if a compiler does not support C++23's #elifdef/#elifndef
// directives then the "unexpected" block (see below) will be selected.
#ifdef CPU
std::cout << "4: no1\n";
#elifdef GPU
std::cout << "4: no2\n";
#elifndef RAM
std::cout << "4: yes\n"; // expected block
#else
std::cout << "4: no!\n"; // unexpectedly selects this block by skipping
// unknown directives and "jumping" directly
// from "#ifdef CPU" to this "#else" block
#endif

// To fix the problem above we may conditionally define the
// macro ELIFDEF_SUPPORTED only if the C++23 directives
// #elifdef/#elifndef are supported.
#if 0
#elifndef UNDEFINED_MACRO
#define ELIFDEF_SUPPORTED
#else
#endif

#ifdef ELIFDEF_SUPPORTED
#ifdef CPU
std::cout << "4: no1\n";
#elifdef GPU
std::cout << "4: no2\n";
#elifndef RAM
std::cout << "4: yes\n"; // expected block
#else
std::cout << "4: no3\n";
#endif
#else // when #elifdef unsupported use old verbose `#elif defined`
#ifdef CPU
std::cout << "4: no1\n";
#elif defined GPU
std::cout << "4: no2\n";
#elif !defined RAM
std::cout << "4: yes\n"; // expected block
#else
std::cout << "4: no3\n";
#endif
#endif

}
4 changes: 4 additions & 0 deletions cxx-squid/src/test/resources/parser/own/C++23/warning.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#error
#error "diagnostic-message"
#warning
#warning "diagnostic-message (since C++23)"

0 comments on commit 9cb98e6

Please sign in to comment.