llvm-project/clang/test/Preprocessor/ext-pp-directive.c
Ken Matsui a1545f51a9 Warn if using elifdef & elifndef in not C2x & C++2b mode
This adds an extension warning when using the preprocessor conditionals
in a language mode they're not officially supported in, and an opt-in
warning for compatibility with previous standards.

Fixes #55306
Differential Revision: https://reviews.llvm.org/D125178
2022-05-12 09:26:44 -04:00

60 lines
2.5 KiB
C

// 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 '#elifdef' directive is a C2x extension}}
// pre-c2x-compat-warning@-4 {{use of a '#elifdef' directive is incompatible with C standards before C2x}}
// For C++
// pre-cpp2b-pedantic-warning@-7 {{use of a '#elifdef' directive is a C++2b extension}}
// pre-cpp2b-compat-warning@-8 {{use of a '#elifdef' directive is incompatible with C++ standards before C++2b}}
#if 0
#elifndef D
#endif
// For C
// pre-c2x-pedantic-warning@-3 {{use of a '#elifndef' directive is a C2x extension}}
// pre-c2x-compat-warning@-4 {{use of a '#elifndef' directive is incompatible with C standards before C2x}}
// For C++
// pre-cpp2b-pedantic-warning@-7 {{use of a '#elifndef' directive is a C++2b extension}}
// pre-cpp2b-compat-warning@-8 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}}