<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/90596>90596</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Overzealous -Wstrict-prototypes warnings on function definitions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jmarshall
      </td>
    </tr>
</table>

<pre>
    Consider the following, _foo.c_:

```c
int foo() {
    return 42;
}
```

Current clang (19.0.0git c3598b161a4d868b1cd10a7ee7ac37d68e5a36fe) with `-pedantic` or `-Wstrict-prototypes` produces a warning for this code:

```
clang -c -Wstrict-prototypes foo.c 
foo.c:1:8: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
    1 | int foo() {
      |        ^
      |         void
```

The discussion in [[RFC] Enabling -Wstrict-prototypes by default in C](https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521) largely focusses on encouraging users to write declarations as `int foo(void);` but I am interested in the application of this warning to function **definitions**.

The diagnostic message above is somewhat confusing as this is a function definition, not just a function declaration. More importantly, I believe there is no confusion about a function definition with an empty parameter list. In particular C17 N2176 §6.7.6.3/14 says [similar text appears in earlier versions; emphasis added]

> An identifier list declares only the identifiers of the parameters of the function. **An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.** The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied. [Footnote 147: See “future language directions” (6.11.6).]

I would take this to mean that a function **definition** with an empty parameter list effectively provides a prototype, and therefore that the warning is spurious in this case. It seems unfortunate to encourage users to hypercorrect their code to define such functions as `int foo(void) { return 42; }` when the `void` doesn't add anything in a function **definition**.


I also tried to find the chapter and verse of the standard saying that this scenario is “deprecated in all versions of C”. I guess this is based on §6.11.6, which says

> The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.

Based on the two “…empty list…” sentences in the paragraph quoted above whose footnote refers to §6.11.6 and the fact that the obsolescent feature we're trying to get rid of in §6.11.6 is non-prototype declarations, I think this sentence intends only to refer to the latter and should perhaps read

> The use of function declarators **(that are not part of definitions of the respective functions)** with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.

in which case it would not provide motivation for emitting this warning on function **definitions**. (I did not see a defect report to this effect or otherwise relating to §6.11.6.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V12P47oN_TXKCxHDlhM7echDJrMB5qEt0Bbo4wVt0bH2OpIryUnTX1_QsvOxO7uL24e7WMx4bIciD885ZNB7fTJEO7F-E-v3BQ6htW739YzOt9h1i8qq2-5gjdeKHISWoLFdZ6_anIQ8wG-NtUn9m8j3In0X6fyzSOP_Ov6tTYDGWiE3Qm5BlG_xNgCAozA4Aysp8umuKN-_ifIc-jA4RyZA3aE5gZCbbJukSXrSAep8vd1UWZHhSm2KTZXVKkuxJCqxzktVbGiNedEQ53DVoQVRpMueFJqga1GkYN14618-OF2HZe9ssOHWk-eHvbNqqMkDwhWd0eYEjWVEtIfaKvoRBPHPmO6yhk-iw4ghxBfHa5HvM5HvNyLfz4fxJUIzmDpoa0BR3aHD8ZprsUMAhHtM0B4U9Y5qDKRAG8Cugws5r63xYBs4gFi_fVbq-v3RnAxEeYCfdA_GF6Z_Yv3lB0_gYrX6SVP_2RIo7evBc36c7kjHt78fD2L9Dl8MVh0D_hl41Q0UNTh0gT_H7wu5aUPoPXdEHoU8cmg7OE9J113OiXUnIY9ByKNr6iVNwZfX72Ivq9tyir3UZlkLeSzStcwYhg7dibobNJazJg_WABk-Bk-c6uDJeQgWrk4Heu6XB_TMswesIzpyywooUqiGAB-AZ8adHPmpgSw97PtO17Hrtoncm8kY7IMdQu6F3CtqtNHjkfFG8j3meDLWB13DmbzHEwFW9jLSx9szXVsMUFvTDJ6PQB-P1P6VivMxbAjGBvg6-PADsibwF-sI9Lm3LqAJ3Y0_9AEV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