SCons / scons

SCons - a software construction tool
http://scons.org
MIT License
2.05k stars 312 forks source link

C/C++ scanner: add #elifdef and #elifndef #4518

Open delan opened 4 months ago

delan commented 4 months ago

C++23 introduces #elifdef and #elifdef in the preprocessor: https://en.cppreference.com/w/cpp/preprocessor/conditional

// 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
mwichmann commented 4 months ago

Applies to C23 as well. For grins, here's the example from the C standard:

#ifdef __STDC__
#define TITLE "ISO C Compilation"
#elifndef __cplusplus
#define TITLE "Non-ISO C Compilation"
#else
/* C++ */
#define