[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 1 07:01:11 PDT 2022


cor3ntin added inline comments.


================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:5566-5567
+def warn_non_prototype_changes_behavior : Warning<
+  "this function declaration without a prototype is deprecated in all versions "
+  "of C and changes behavior in C2x">, InGroup<DeprecatedNonPrototype>;
+def warn_prototype_changes_behavior : Warning<
----------------
"declaration of a function without a prototype is deprecated", may be slightly better?


================
Comment at: clang/lib/Sema/SemaDecl.cpp:3881
+      if (WithProto->getNumParams() != 0) {
+        // The function definition has parameters, so this will change
+        // behavior in C2x.
----------------
I wonder if

  - This shouldn't be placed in a separate function for clarity
  - We  could bail out early for built ins ?




================
Comment at: clang/lib/Sema/SemaType.cpp:5560-5562
   if (!LangOpts.CPlusPlus &&
-      D.getFunctionDefinitionKind() == FunctionDefinitionKind::Declaration) {
+      (D.getFunctionDefinitionKind() == FunctionDefinitionKind::Declaration ||
+       D.getFunctionDefinitionKind() == FunctionDefinitionKind::Definition)) {
----------------
`if (!LangOpts.CPlusPlus)` is probably enough here


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122895/new/

https://reviews.llvm.org/D122895



More information about the cfe-commits mailing list