[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGa1545f51a9ef: Warn if using `elifdef` `elifndef` in not C2x C++2b mode (authored by ken-matsui, committed by aaron.ballman). Changed prior to commit: https://reviews.llvm.org/D125178?vs=428910=428924#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 Files: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticLexKinds.td clang/lib/Lex/PPDirectives.cpp clang/test/Lexer/Inputs/unsafe-macro-2.h clang/test/Lexer/deprecate-macro.c clang/test/Preprocessor/elifdef.c clang/test/Preprocessor/ext-pp-directive.c clang/test/Preprocessor/if_warning.c clang/test/Preprocessor/ifdef-recover.c clang/test/Preprocessor/macro_misc.c clang/test/Preprocessor/macro_vaopt_check.cpp Index: clang/test/Preprocessor/macro_vaopt_check.cpp === --- clang/test/Preprocessor/macro_vaopt_check.cpp +++ clang/test/Preprocessor/macro_vaopt_check.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++20 -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++11 -// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -pedantic -std=c99 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++20 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++11 +// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -Wno-c2x-extensions -pedantic -std=c99 //expected-error@+1{{missing '('}} #define V1(...) __VA_OPT__ Index: clang/test/Preprocessor/macro_misc.c === --- clang/test/Preprocessor/macro_misc.c +++ clang/test/Preprocessor/macro_misc.c @@ -4,6 +4,7 @@ #ifdef defined #elifdef defined #endif +// expected-warning@-2 {{use of a '#elifdef' directive is a C2x extension}} Index: clang/test/Preprocessor/ifdef-recover.c === --- clang/test/Preprocessor/ifdef-recover.c +++ clang/test/Preprocessor/ifdef-recover.c @@ -19,12 +19,14 @@ #if f(2 #endif -/* expected-error@+2 {{macro name missing}} */ +/* expected-error@+3 {{macro name missing}} */ +/* expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} */ #ifdef FOO #elifdef #endif -/* expected-error@+2 {{macro name must be an identifier}} */ +/* expected-error@+3 {{macro name must be an identifier}} */ +/* expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} */ #ifdef FOO #elifdef ! #endif Index: clang/test/Preprocessor/if_warning.c === --- clang/test/Preprocessor/if_warning.c +++ clang/test/Preprocessor/if_warning.c @@ -5,6 +5,7 @@ #if foo // expected-error {{'foo' is not defined, evaluates to 0}} #endif +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef foo #elifdef foo #endif @@ -14,6 +15,7 @@ // PR3938 +// expected-warning@+3 {{use of a '#elifdef' directive is a C2x extension}} #if 0 #ifdef D #elifdef D Index: clang/test/Preprocessor/ext-pp-directive.c === --- /dev/null +++ clang/test/Preprocessor/ext-pp-directive.c @@ -0,0 +1,59 @@ +// For C +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=pre-c2x-pedantic -pedantic %s +// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=pre-c2x-compat -Wpre-c2x-compat %s +// RUN: not %clang_cc1 -std=c99 -fsyntax-only -verify %s +// RUN: not %clang_cc1 -std=c2x -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -std=c2x -fsyntax-only -verify %s + +// For C++ +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=pre-cpp2b-pedantic -pedantic %s +// RUN: %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify=pre-cpp2b-compat -Wpre-c++2b-compat %s +// RUN: not %clang_cc1 -x c++ -fsyntax-only -verify %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify %s + +int x; + +#if 1 +#elifdef A // #1 +#endif +// For C +// pre-c2x-pedantic-warning@#1 {{use of a '#elifdef' directive is a C2x extension}} +// pre-c2x-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C standards before C2x}} + +// For C++ +// pre-cpp2b-pedantic-warning@#1 {{use of a '#elifdef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}} + +#if 1 +#elifndef B // #2 +#endif +// For C +// pre-c2x-pedantic-warning@#2 {{use of a '#elifndef' directive is a C2x extension}} +// pre-c2x-compat-warning@#2 {{use of a '#elifndef' directive is incompatible with C standards before C2x}} + +// For C++ +// pre-cpp2b-pedantic-warning@#2
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
ken-matsui added a comment. I fixed it! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
ken-matsui updated this revision to Diff 428910. ken-matsui added a comment. Fix the failed test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 Files: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticLexKinds.td clang/lib/Lex/PPDirectives.cpp clang/test/Lexer/Inputs/unsafe-macro-2.h clang/test/Lexer/deprecate-macro.c clang/test/Preprocessor/elifdef.c clang/test/Preprocessor/ext-pp-directive.c clang/test/Preprocessor/if_warning.c clang/test/Preprocessor/ifdef-recover.c clang/test/Preprocessor/macro_misc.c clang/test/Preprocessor/macro_vaopt_check.cpp Index: clang/test/Preprocessor/macro_vaopt_check.cpp === --- clang/test/Preprocessor/macro_vaopt_check.cpp +++ clang/test/Preprocessor/macro_vaopt_check.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++20 -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++11 -// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -pedantic -std=c99 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++20 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++11 +// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -Wno-c2x-extensions -pedantic -std=c99 //expected-error@+1{{missing '('}} #define V1(...) __VA_OPT__ Index: clang/test/Preprocessor/macro_misc.c === --- clang/test/Preprocessor/macro_misc.c +++ clang/test/Preprocessor/macro_misc.c @@ -4,6 +4,7 @@ #ifdef defined #elifdef defined #endif +// expected-warning@-2 {{use of a '#elifdef' directive is a C2x extension}} Index: clang/test/Preprocessor/ifdef-recover.c === --- clang/test/Preprocessor/ifdef-recover.c +++ clang/test/Preprocessor/ifdef-recover.c @@ -19,12 +19,14 @@ #if f(2 #endif -/* expected-error@+2 {{macro name missing}} */ +/* expected-error@+3 {{macro name missing}} */ +/* expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} */ #ifdef FOO #elifdef #endif -/* expected-error@+2 {{macro name must be an identifier}} */ +/* expected-error@+3 {{macro name must be an identifier}} */ +/* expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} */ #ifdef FOO #elifdef ! #endif Index: clang/test/Preprocessor/if_warning.c === --- clang/test/Preprocessor/if_warning.c +++ clang/test/Preprocessor/if_warning.c @@ -5,6 +5,7 @@ #if foo // expected-error {{'foo' is not defined, evaluates to 0}} #endif +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef foo #elifdef foo #endif @@ -14,6 +15,7 @@ // PR3938 +// expected-warning@+3 {{use of a '#elifdef' directive is a C2x extension}} #if 0 #ifdef D #elifdef D Index: clang/test/Preprocessor/ext-pp-directive.c === --- /dev/null +++ clang/test/Preprocessor/ext-pp-directive.c @@ -0,0 +1,59 @@ +// For C +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=pre-c2x-pedantic -pedantic %s +// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=pre-c2x-compat -Wpre-c2x-compat %s +// RUN: not %clang_cc1 -std=c99 -fsyntax-only -verify %s +// RUN: not %clang_cc1 -std=c2x -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -std=c2x -fsyntax-only -verify %s + +// For C++ +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=pre-cpp2b-pedantic -pedantic %s +// RUN: %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify=pre-cpp2b-compat -Wpre-c++2b-compat %s +// RUN: not %clang_cc1 -x c++ -fsyntax-only -verify %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify %s + +int x; + +#if 1 +#elifdef A // #1 +#endif +// For C +// pre-c2x-pedantic-warning@#1 {{use of a '#elifdef' directive is a C2x extension}} +// pre-c2x-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C standards before C2x}} + +// For C++ +// pre-cpp2b-pedantic-warning@#1 {{use of a '#elifdef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}} + +#if 1 +#elifndef B // #2 +#endif +// For C +// pre-c2x-pedantic-warning@#2 {{use of a '#elifndef' directive is a C2x extension}} +// pre-c2x-compat-warning@#2 {{use of a '#elifndef' directive is incompatible with C standards before C2x}} + +// For C++ +// pre-cpp2b-pedantic-warning@#2 {{use of a '#elifndef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#2 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}} + +#if 0 +#elifdef C +#endif +// For C +// pre-c2x-pedantic-warning@-3 {{use of a
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
aaron.ballman added a comment. Oops, it looks like precommit CI found a relevant issue, can you fix it up? Failed Tests (1): Clang :: Preprocessor/elifdef.c Testing Time: 790.67s Skipped :56 Unsupported : 1997 Passed : 87720 Expectedly Failed: 234 Failed : 1 Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
ken-matsui added a comment. Thank you so much for your review! My public email address is: `07softy_br...@icloud.com`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
ken-matsui updated this revision to Diff 428840. ken-matsui added a comment. Updated the code as reviewed, added a release note, and merged `ext-cpp2b-pp-directive.cpp` & `ext-c2x-pp-directive.c` into `ext-pp-directive.c`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 Files: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticLexKinds.td clang/lib/Lex/PPDirectives.cpp clang/test/Lexer/Inputs/unsafe-macro-2.h clang/test/Lexer/deprecate-macro.c clang/test/Preprocessor/elifdef.c clang/test/Preprocessor/ext-pp-directive.c clang/test/Preprocessor/if_warning.c clang/test/Preprocessor/ifdef-recover.c clang/test/Preprocessor/macro_misc.c clang/test/Preprocessor/macro_vaopt_check.cpp Index: clang/test/Preprocessor/macro_vaopt_check.cpp === --- clang/test/Preprocessor/macro_vaopt_check.cpp +++ clang/test/Preprocessor/macro_vaopt_check.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++20 -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++11 -// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -pedantic -std=c99 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++20 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++11 +// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -Wno-c2x-extensions -pedantic -std=c99 //expected-error@+1{{missing '('}} #define V1(...) __VA_OPT__ Index: clang/test/Preprocessor/macro_misc.c === --- clang/test/Preprocessor/macro_misc.c +++ clang/test/Preprocessor/macro_misc.c @@ -4,6 +4,7 @@ #ifdef defined #elifdef defined #endif +// expected-warning@-2 {{use of a '#elifdef' directive is a C2x extension}} Index: clang/test/Preprocessor/ifdef-recover.c === --- clang/test/Preprocessor/ifdef-recover.c +++ clang/test/Preprocessor/ifdef-recover.c @@ -19,12 +19,14 @@ #if f(2 #endif -/* expected-error@+2 {{macro name missing}} */ +/* expected-error@+3 {{macro name missing}} */ +/* expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} */ #ifdef FOO #elifdef #endif -/* expected-error@+2 {{macro name must be an identifier}} */ +/* expected-error@+3 {{macro name must be an identifier}} */ +/* expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} */ #ifdef FOO #elifdef ! #endif Index: clang/test/Preprocessor/if_warning.c === --- clang/test/Preprocessor/if_warning.c +++ clang/test/Preprocessor/if_warning.c @@ -5,6 +5,7 @@ #if foo // expected-error {{'foo' is not defined, evaluates to 0}} #endif +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef foo #elifdef foo #endif @@ -14,6 +15,7 @@ // PR3938 +// expected-warning@+3 {{use of a '#elifdef' directive is a C2x extension}} #if 0 #ifdef D #elifdef D Index: clang/test/Preprocessor/ext-pp-directive.c === --- /dev/null +++ clang/test/Preprocessor/ext-pp-directive.c @@ -0,0 +1,59 @@ +// For C +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=pre-c2x-pedantic -pedantic %s +// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=pre-c2x-compat -Wpre-c2x-compat %s +// RUN: not %clang_cc1 -std=c99 -fsyntax-only -verify %s +// RUN: not %clang_cc1 -std=c2x -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -std=c2x -fsyntax-only -verify %s + +// For C++ +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=pre-cpp2b-pedantic -pedantic %s +// RUN: %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify=pre-cpp2b-compat -Wpre-c++2b-compat %s +// RUN: not %clang_cc1 -x c++ -fsyntax-only -verify %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify %s + +int x; + +#if 1 +#elifdef A // #1 +#endif +// For C +// pre-c2x-pedantic-warning@#1 {{use of a '#elifdef' directive is a C2x extension}} +// pre-c2x-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C standards before C2x}} + +// For C++ +// pre-cpp2b-pedantic-warning@#1 {{use of a '#elifdef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}} + +#if 1 +#elifndef B // #2 +#endif +// For C +// pre-c2x-pedantic-warning@#2 {{use of a '#elifndef' directive is a C2x extension}} +// pre-c2x-compat-warning@#2 {{use of a '#elifndef' directive is incompatible with C standards before C2x}} + +// For C++ +// pre-cpp2b-pedantic-warning@#2 {{use of a '#elifndef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#2 {{use of a '#elifndef' directive is
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM aside from a super minor nit in a test file. Can you please add a release note for the new diagnostics as well? I'm happy to land this for you when you're ready, but let me know which email address you'd like me to use this time around. Comment at: clang/test/Preprocessor/ifdef-recover.c:23-29 +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef FOO #elifdef #endif -/* expected-error@+2 {{macro name must be an identifier}} */ +/* expected-error@+3 {{macro name must be an identifier}} */ +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} Just to keep comment styles the same. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
ken-matsui added a comment. Thank you for your review! I updated the code. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
ken-matsui updated this revision to Diff 428636. ken-matsui added a comment. Update the code as reviewed Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 Files: clang/include/clang/Basic/DiagnosticLexKinds.td clang/lib/Lex/PPDirectives.cpp clang/test/Lexer/Inputs/unsafe-macro-2.h clang/test/Lexer/deprecate-macro.c clang/test/Preprocessor/elifdef.c clang/test/Preprocessor/ext-c2x-pp-directive.c clang/test/Preprocessor/ext-cpp2b-pp-directive.cpp clang/test/Preprocessor/if_warning.c clang/test/Preprocessor/ifdef-recover.c clang/test/Preprocessor/macro_misc.c clang/test/Preprocessor/macro_vaopt_check.cpp Index: clang/test/Preprocessor/macro_vaopt_check.cpp === --- clang/test/Preprocessor/macro_vaopt_check.cpp +++ clang/test/Preprocessor/macro_vaopt_check.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++20 -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++11 -// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -pedantic -std=c99 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++20 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++11 +// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -Wno-c2x-extensions -pedantic -std=c99 //expected-error@+1{{missing '('}} #define V1(...) __VA_OPT__ Index: clang/test/Preprocessor/macro_misc.c === --- clang/test/Preprocessor/macro_misc.c +++ clang/test/Preprocessor/macro_misc.c @@ -4,6 +4,7 @@ #ifdef defined #elifdef defined #endif +// expected-warning@-2 {{use of a '#elifdef' directive is a C2x extension}} Index: clang/test/Preprocessor/ifdef-recover.c === --- clang/test/Preprocessor/ifdef-recover.c +++ clang/test/Preprocessor/ifdef-recover.c @@ -19,12 +19,14 @@ #if f(2 #endif -/* expected-error@+2 {{macro name missing}} */ +/* expected-error@+3 {{macro name missing}} */ +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef FOO #elifdef #endif -/* expected-error@+2 {{macro name must be an identifier}} */ +/* expected-error@+3 {{macro name must be an identifier}} */ +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef FOO #elifdef ! #endif Index: clang/test/Preprocessor/if_warning.c === --- clang/test/Preprocessor/if_warning.c +++ clang/test/Preprocessor/if_warning.c @@ -5,6 +5,7 @@ #if foo // expected-error {{'foo' is not defined, evaluates to 0}} #endif +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef foo #elifdef foo #endif @@ -14,6 +15,7 @@ // PR3938 +// expected-warning@+3 {{use of a '#elifdef' directive is a C2x extension}} #if 0 #ifdef D #elifdef D Index: clang/test/Preprocessor/ext-cpp2b-pp-directive.cpp === --- /dev/null +++ clang/test/Preprocessor/ext-cpp2b-pp-directive.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=pre-cpp2b-pedantic -pedantic %s +// RUN: %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify=pre-cpp2b-compat -Wpre-c++2b-compat %s +// RUN: not %clang_cc1 -x c++ -fsyntax-only -verify %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify %s + +int x; + +#if 1 +#elifdef A // #1 +#endif +// pre-cpp2b-pedantic-warning@#1 {{use of a '#elifdef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}} + +#if 1 +#elifndef B // #2 +#endif +// pre-cpp2b-pedantic-warning@#2 {{use of a '#elifndef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#2 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}} + +#if 0 +#elifdef C +#endif +// pre-cpp2b-pedantic-warning@-2 {{use of a '#elifdef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@-3 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}} + +#if 0 +#elifndef D +#endif +// pre-cpp2b-pedantic-warning@-2 {{use of a '#elifndef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@-3 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}} Index: clang/test/Preprocessor/ext-c2x-pp-directive.c === --- /dev/null +++ clang/test/Preprocessor/ext-c2x-pp-directive.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=c99-pedantic -pedantic %s +// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=pre-c2x-compat -Wpre-c2x-compat %s +// RUN: not
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
aaron.ballman added inline comments. Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:698 +def warn_c2x_compat_pp_directive : Warning< + "use of a '#%select{elifdef|elifndef}0' directive is incompatible with C standards before C2x">, + InGroup, DefaultIgnore; (You may also need to rewrap to 80 col limits.) And do the same for the other three, so that you can use `PPElifDiag` for it. Comment at: clang/lib/Lex/PPDirectives.cpp:663 + +Diag(Tok, DiagID) << (IsElifDef ? PED_Elifdef : PED_Elifndef) - 1; + I like the way you're thinking about this, but I don't like how clever the code is. I'd rather update the comment on `PPElifDiag` to mention `warn_*_compat_pp_directive` and `ext_*_pp_directive`, and then update those diagnostics to have a bogus select slot for the `PED_Elif` that will never be used. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode
ken-matsui updated this revision to Diff 428435. ken-matsui added a comment. Fix failed tests Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125178/new/ https://reviews.llvm.org/D125178 Files: clang/include/clang/Basic/DiagnosticLexKinds.td clang/lib/Lex/PPDirectives.cpp clang/test/Lexer/Inputs/unsafe-macro-2.h clang/test/Lexer/deprecate-macro.c clang/test/Preprocessor/elifdef.c clang/test/Preprocessor/ext-c2x-pp-directive.c clang/test/Preprocessor/ext-cpp2b-pp-directive.cpp clang/test/Preprocessor/if_warning.c clang/test/Preprocessor/ifdef-recover.c clang/test/Preprocessor/macro_misc.c clang/test/Preprocessor/macro_vaopt_check.cpp Index: clang/test/Preprocessor/macro_vaopt_check.cpp === --- clang/test/Preprocessor/macro_vaopt_check.cpp +++ clang/test/Preprocessor/macro_vaopt_check.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++20 -// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -pedantic -std=c++11 -// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -pedantic -std=c99 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++20 +// RUN: %clang_cc1 %s -Eonly -verify -Wno-all -Wno-c++2b-extensions -pedantic -std=c++11 +// RUN: %clang_cc1 -x c %s -Eonly -verify -Wno-all -Wno-c2x-extensions -pedantic -std=c99 //expected-error@+1{{missing '('}} #define V1(...) __VA_OPT__ Index: clang/test/Preprocessor/macro_misc.c === --- clang/test/Preprocessor/macro_misc.c +++ clang/test/Preprocessor/macro_misc.c @@ -4,6 +4,7 @@ #ifdef defined #elifdef defined #endif +// expected-warning@-2 {{use of a '#elifdef' directive is a C2x extension}} Index: clang/test/Preprocessor/ifdef-recover.c === --- clang/test/Preprocessor/ifdef-recover.c +++ clang/test/Preprocessor/ifdef-recover.c @@ -19,12 +19,14 @@ #if f(2 #endif -/* expected-error@+2 {{macro name missing}} */ +/* expected-error@+3 {{macro name missing}} */ +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef FOO #elifdef #endif -/* expected-error@+2 {{macro name must be an identifier}} */ +/* expected-error@+3 {{macro name must be an identifier}} */ +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef FOO #elifdef ! #endif Index: clang/test/Preprocessor/if_warning.c === --- clang/test/Preprocessor/if_warning.c +++ clang/test/Preprocessor/if_warning.c @@ -5,6 +5,7 @@ #if foo // expected-error {{'foo' is not defined, evaluates to 0}} #endif +// expected-warning@+2 {{use of a '#elifdef' directive is a C2x extension}} #ifdef foo #elifdef foo #endif @@ -14,6 +15,7 @@ // PR3938 +// expected-warning@+3 {{use of a '#elifdef' directive is a C2x extension}} #if 0 #ifdef D #elifdef D Index: clang/test/Preprocessor/ext-cpp2b-pp-directive.cpp === --- /dev/null +++ clang/test/Preprocessor/ext-cpp2b-pp-directive.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=pre-cpp2b-pedantic -pedantic %s +// RUN: %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify=pre-cpp2b-compat -Wpre-c++2b-compat %s +// RUN: not %clang_cc1 -x c++ -fsyntax-only -verify %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify -pedantic %s +// RUN: not %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify %s + +int x; + +#if 1 +#elifdef A // #1 +#endif +// pre-cpp2b-pedantic-warning@#1 {{use of a '#elifdef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#1 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}} + +#if 1 +#elifndef B // #2 +#endif +// pre-cpp2b-pedantic-warning@#2 {{use of a '#elifndef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@#2 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}} + +#if 0 +#elifdef C +#endif +// pre-cpp2b-pedantic-warning@-2 {{use of a '#elifdef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@-3 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}} + +#if 0 +#elifndef D +#endif +// pre-cpp2b-pedantic-warning@-2 {{use of a '#elifndef' directive is a C++2b extension}} +// pre-cpp2b-compat-warning@-3 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}} Index: clang/test/Preprocessor/ext-c2x-pp-directive.c === --- /dev/null +++ clang/test/Preprocessor/ext-c2x-pp-directive.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=c99-pedantic -pedantic %s +// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=pre-c2x-compat -Wpre-c2x-compat %s +// RUN: not %clang_cc1