Functions without prototypes in C (also known as K&R C functions) were introduced into C89 as a deprecated feature and C2x is now reclaiming that syntax space with different semantics. However, Clang's -Wstrict-prototypes diagnostic is off-by-default (even in pedantic mode) and does not suffice to warn users about issues in their code. This patch changes the behavior of -Wstrict-prototypes to only diagnose declarations and definitions which are not going to change behavior in C2x mode, and enables the diagnostic in -pedantic mode. The diagnostic is now specifically about the fact that the feature is deprecated. It also adds -Wdeprecated-non-prototype, which is grouped under -Wstrict-prototypes and diagnoses declarations or definitions which will change behavior in C2x mode. This diagnostic is enabled by default because the risk is higher for the user to continue to use the deprecated feature. Differential Revision: https://reviews.llvm.org/D122895
19 lines
860 B
C
19 lines
860 B
C
// RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify -std=c99
|
|
// RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify -DPREDECLARE -std=c99
|
|
|
|
#ifdef PREDECLARE
|
|
// PR16344
|
|
// Clang has defined 'vfprint' in builtin list. If the following line occurs before any other
|
|
// `vfprintf' in this file, and we getPreviousDecl()->getTypeSourceInfo() on it, then we will
|
|
// get a null pointer since the one in builtin list doesn't has valid TypeSourceInfo.
|
|
int vfprintf(void) { return 0; } // expected-warning {{requires inclusion of the header <stdio.h>}}
|
|
#endif
|
|
|
|
// PR4290
|
|
// The following declaration is compatible with vfprintf, so we shouldn't
|
|
// reject.
|
|
int vfprintf(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
|
|
#ifndef PREDECLARE
|
|
// expected-warning@-2 {{requires inclusion of the header <stdio.h>}}
|
|
#endif
|