llvm-capstone/clang/test/Preprocessor/macro_misc.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

40 lines
1.1 KiB
C

// RUN: %clang_cc1 %s -Eonly -verify
// This should not be rejected.
#ifdef defined
#elifdef defined
#endif
// expected-warning@-2 {{use of a '#elifdef' directive is a C2x extension}}
// PR3764
// This should not produce a redefinition warning.
#define FUNC_LIKE(a) (a)
#define FUNC_LIKE(a)(a)
// This either.
#define FUNC_LIKE2(a)\
(a)
#define FUNC_LIKE2(a) (a)
// This should.
#define FUNC_LIKE3(a) ( a) // expected-note {{previous definition is here}}
#define FUNC_LIKE3(a) (a) // expected-warning {{'FUNC_LIKE3' macro redefined}}
// RUN: %clang_cc1 -fms-extensions -DMS_EXT %s -Eonly -verify
#ifndef MS_EXT
// This should under C99.
#define FUNC_LIKE4(a,b) (a+b) // expected-note {{previous definition is here}}
#define FUNC_LIKE4(x,y) (x+y) // expected-warning {{'FUNC_LIKE4' macro redefined}}
#else
// This shouldn't under MS extensions.
#define FUNC_LIKE4(a,b) (a+b)
#define FUNC_LIKE4(x,y) (x+y)
// This should.
#define FUNC_LIKE5(a,b) (a+b) // expected-note {{previous definition is here}}
#define FUNC_LIKE5(x,y) (y+x) // expected-warning {{'FUNC_LIKE5' macro redefined}}
#endif