[all-commits] [llvm/llvm-project] 2f26bc: Warn about zero-parameter K&R definitions in -Wstr...

Aaron Puchert via All-commits all-commits at lists.llvm.org
Fri Feb 14 10:25:25 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 2f26bc5542705c390bf17af2fdfc31e056147ea9
      https://github.com/llvm/llvm-project/commit/2f26bc5542705c390bf17af2fdfc31e056147ea9
  Author: Aaron Puchert <aaronpuchert at alice-dsl.net>
  Date:   2020-02-14 (Fri, 14 Feb 2020)

  Changed paths:
    M clang/lib/Sema/SemaDecl.cpp
    M clang/test/Sema/warn-strict-prototypes.c
    A clang/test/Sema/warn-strict-prototypes.cpp
    M clang/test/Sema/warn-strict-prototypes.m

  Log Message:
  -----------
  Warn about zero-parameter K&R definitions in -Wstrict-prototypes

Summary:
Zero-parameter K&R definitions specify that the function has no
parameters, but they are still not prototypes, so calling the function
with the wrong number of parameters is just a warning, not an error.

The C11 standard doesn't seem to directly define what a prototype is,
but it can be inferred from 6.9.1p7: "If the declarator includes a
parameter type list, the list also specifies the types of all the
parameters; such a declarator also serves as a function prototype
for later calls to the same function in the same translation unit."
This refers to 6.7.6.3p5: "If, in the declaration “T D1”, D1 has
the form
    D(parameter-type-list)
or
    D(identifier-list_opt)
[...]". Later in 6.11.7 it also refers only to the parameter-type-list
variant as prototype: "The use of function definitions with separate
parameter identifier and declaration lists (not prototype-format
parameter type and identifier declarators) is an obsolescent feature."

We already correctly treat an empty parameter list as non-prototype
declaration, so we can just take that information.

GCC also warns about this with -Wstrict-prototypes.

This shouldn't affect C++, because there all FunctionType's are
FunctionProtoTypes. I added a simple test for that.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D66919




More information about the All-commits mailing list