llvm-project/clang/test/Sema/warn-mixed-decls.c
Marco Elver c65186c89f [clang] Improve -Wdeclaration-after-statement
With 118f966b46cf, Clang matches GCC's behaviour and allows enabling
-Wdeclaration-after-statement with C99 and later.

However, the check for mixing declarations and code is not a constant time
algorithm, and therefore should be guarded with Diags.isIgnored().

Furthermore, improve test coverage with: non-pedantic C89 with the
warning; C11 with the warning; and when using -Wall.

Finally, mention the changed behaviour in ReleaseNotes.rst.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D117232
2022-01-20 19:56:34 +01:00

39 lines
1.2 KiB
C

/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -Wdeclaration-after-statement %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -Wdeclaration-after-statement %s
*/
/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 -Wall %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 -Wall -pedantic %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c11 -Wall -pedantic %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
*/
/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ -Wdeclaration-after-statement %s
*/
/* none-no-diagnostics */
int foo(int i)
{
i += 1;
int f = i;
#if __STDC_VERSION__ < 199901L
/* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
#else
/* expected-warning@-4 {{mixing declarations and code is incompatible with standards before C99}}*/
#endif
return f;
}