[clang] ef87865 - Silence -Wstrict-prototype diagnostics in C2x mode
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 29 10:37:41 PDT 2022
Author: Aaron Ballman
Date: 2022-04-29T13:37:33-04:00
New Revision: ef87865b98fa25af1d2c045bab1268b2a1503374
URL: https://github.com/llvm/llvm-project/commit/ef87865b98fa25af1d2c045bab1268b2a1503374
DIFF: https://github.com/llvm/llvm-project/commit/ef87865b98fa25af1d2c045bab1268b2a1503374.diff
LOG: Silence -Wstrict-prototype diagnostics in C2x mode
This also disables the diagnostic when the user passes -fno-knr-functions.
Added:
clang/test/Sema/c2x-warn-strict-prototypes.c
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 652ef45b24df..91944e0b11ef 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,14 +149,17 @@ Improvements to Clang's diagnostics
now only diagnose deprecated declarations and definitions of functions
without a prototype where the behavior in C2x will remain correct. This
diagnostic remains off by default but is now enabled via ``-pedantic`` due to
- it being a deprecation warning. ``-Wdeprecated-non-prototype`` will diagnose
- cases where the deprecated declarations or definitions of a function without
- a prototype will change behavior in C2x. Additionally, it will diagnose calls
- which pass arguments to a function without a prototype. This warning is
- enabled only when the ``-Wdeprecated-non-prototype`` option is enabled at the
- function declaration site, which allows a developer to disable the diagnostic
- for all callers at the point of declaration. This diagnostic is grouped under
- the ``-Wstrict-prototypes`` warning group, but is enabled by default.
+ it being a deprecation warning. ``-Wstrict-prototypes`` has no effect in C2x
+ or when ``-fno-knr-functions`` is enabled. ``-Wdeprecated-non-prototype``
+ will diagnose cases where the deprecated declarations or definitions of a
+ function without a prototype will change behavior in C2x. Additionally, it
+ will diagnose calls which pass arguments to a function without a prototype.
+ This warning is enabled only when the ``-Wdeprecated-non-prototype`` option
+ is enabled at the function declaration site, which allows a developer to
+ disable the diagnostic for all callers at the point of declaration. This
+ diagnostic is grouped under the ``-Wstrict-prototypes`` warning group, but is
+ enabled by default. ``-Wdeprecated-non-prototype`` has no effect in C2x or
+ when ``-fno-knr-functions`` is enabled.
- Clang now appropriately issues an error in C when a definition of a function
without a prototype and with no arguments is an invalid redeclaration of a
function with a prototype. e.g., ``void f(int); void f() {}`` is now properly
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6f34e4237bcb..a037956d5e49 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5564,7 +5564,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
// of the parameters is supplied.
// See ActOnFinishFunctionBody() and MergeFunctionDecl() for handling of
// function declarations whose behavior changes in C2x.
- if (!LangOpts.CPlusPlus) {
+ if (!LangOpts.requiresStrictPrototypes()) {
bool IsBlock = false;
for (const DeclaratorChunk &DeclType : D.type_objects()) {
switch (DeclType.Kind) {
diff --git a/clang/test/Sema/c2x-warn-strict-prototypes.c b/clang/test/Sema/c2x-warn-strict-prototypes.c
new file mode 100644
index 000000000000..f3efa1a3aa49
--- /dev/null
+++ b/clang/test/Sema/c2x-warn-strict-prototypes.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify -std=c2x %s
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify -fno-knr-functions %s
+// expected-no-diagnostics
+
+void foo();
+void bar() {}
+
+void baz(void);
+void baz() {}
More information about the cfe-commits
mailing list