Skip to content

Commit ef87865

Browse files
committed
Silence -Wstrict-prototype diagnostics in C2x mode
This also disables the diagnostic when the user passes -fno-knr-functions.
1 parent 7abfaa0 commit ef87865

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,17 @@ Improvements to Clang's diagnostics
149149
now only diagnose deprecated declarations and definitions of functions
150150
without a prototype where the behavior in C2x will remain correct. This
151151
diagnostic remains off by default but is now enabled via ``-pedantic`` due to
152-
it being a deprecation warning. ``-Wdeprecated-non-prototype`` will diagnose
153-
cases where the deprecated declarations or definitions of a function without
154-
a prototype will change behavior in C2x. Additionally, it will diagnose calls
155-
which pass arguments to a function without a prototype. This warning is
156-
enabled only when the ``-Wdeprecated-non-prototype`` option is enabled at the
157-
function declaration site, which allows a developer to disable the diagnostic
158-
for all callers at the point of declaration. This diagnostic is grouped under
159-
the ``-Wstrict-prototypes`` warning group, but is enabled by default.
152+
it being a deprecation warning. ``-Wstrict-prototypes`` has no effect in C2x
153+
or when ``-fno-knr-functions`` is enabled. ``-Wdeprecated-non-prototype``
154+
will diagnose cases where the deprecated declarations or definitions of a
155+
function without a prototype will change behavior in C2x. Additionally, it
156+
will diagnose calls which pass arguments to a function without a prototype.
157+
This warning is enabled only when the ``-Wdeprecated-non-prototype`` option
158+
is enabled at the function declaration site, which allows a developer to
159+
disable the diagnostic for all callers at the point of declaration. This
160+
diagnostic is grouped under the ``-Wstrict-prototypes`` warning group, but is
161+
enabled by default. ``-Wdeprecated-non-prototype`` has no effect in C2x or
162+
when ``-fno-knr-functions`` is enabled.
160163
- Clang now appropriately issues an error in C when a definition of a function
161164
without a prototype and with no arguments is an invalid redeclaration of a
162165
function with a prototype. e.g., ``void f(int); void f() {}`` is now properly

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5564,7 +5564,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
55645564
// of the parameters is supplied.
55655565
// See ActOnFinishFunctionBody() and MergeFunctionDecl() for handling of
55665566
// function declarations whose behavior changes in C2x.
5567-
if (!LangOpts.CPlusPlus) {
5567+
if (!LangOpts.requiresStrictPrototypes()) {
55685568
bool IsBlock = false;
55695569
for (const DeclaratorChunk &DeclType : D.type_objects()) {
55705570
switch (DeclType.Kind) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify -std=c2x %s
2+
// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify -fno-knr-functions %s
3+
// expected-no-diagnostics
4+
5+
void foo();
6+
void bar() {}
7+
8+
void baz(void);
9+
void baz() {}

0 commit comments

Comments
 (0)