[RFC] Enabling -Wstrict-prototypes by default in C

Let me outline what the behavior changes would look like, so we can consider them.

Suppose we add a new diagnostic group that specifically warns about cases that change behavior in C2x. Call it -Wstrict-prototypes-c2x or something like that. This would be three warnings, I think:

  1. a warning on K&R-style definitions (int f() int x; {})
  2. a warning on passing one or more arguments to a function declared without a prototype (int f(); int g(int x) { f(x); })
  3. a warning on redeclaring a function without a prototype with a non-void prototype (int f(); int f(int x) {}).

In particular, we wouldn’t warn on something like void f(); void g() { f(); }. From the user’s perspective, this behaves the same way under the old and new rules.

The advantage here is that users see less warnings. Instead of requiring users to explicitly specify -fstrict-prototypes to silence -Wstrict-prototypes warnings, user code just works transparently across the transition.

The disadvantage is that this is more complicated than just warning directly on int f();. It might be harder for the user to understand why we’re warning in some cases, but not others.

Thanks for the explanation!

The status quo in Clang is that we diagnose deprecated constructs in the language modes they’re obsolete in, and your suggestion elides some of those diagnostics in an effort to be less chatty. That goal is nice and something I’m usually in favor of, but is actually opposed to my goal in this case. I want people to know all the places where they’re using a deprecated feature. Any suggestion which boils down to “don’t warn on this even though it’s deprecated” misses that goal of mine.

I think it’s important to warn on all deprecated uses because I don’t think we can rely on usage catching all of the issues. e.g.,

void func(); // In a header
void func() { } // In a source file, demonstrates the user intended to use void func(void);

You can still call func through inline assembly and pass it arguments without realizing it. You can also use func() properly within your library test suite, but then users of your library accidentally misuse the interface in their code. Also, it’s not clear how to handle cases like using the K&R type in a _Generic selection expression (so there’s no declaration involved, just the type name). Rather than try to chase down answers to all the myriad of ways you can run into these signatures, I think it’s better to just say “spelling the deprecated type gets you a deprecation warning”.

My thinking has been that -Wstrict-prototypes covers exactly the cases I think we need to cover, which is why I was thinking of rewording the diagnostic to be specific to the deprecation issue and then enabling that by default.

That’s why I don’t think changing the heuristics here gains us much. Additional diagnostics on top of the deprecation warning may be worthwhile, but I sort of think -fstrict-prototypes might (maybe) obviate a need for that work. From your three warning suggestions, in that mode: #1 becomes an error (invalid declaration), #2 becomes an error (invalid function call expression), and #3 becomes an error (invalid redeclaration). And there would be no diagnostics with the fourth case you list. So it does cover your use cases, but with errors instead of warnings (which could be a downside).

I believe the difference is specifically for variadic arguments. Fixed arguments, and thus all arguments to prototype-less functions, use the same calling convention, but the lack of a prototype means you risk calling a variadic function incorrectly.

Any function defined with a prototype that involves a parameter of a type that would be subject to the default argument promotions does not need to be callable as an unprototyped function.

| AaronBallman
March 1 |

  • | - |

Thanks for the explanation!

The status quo in Clang is that we diagnose deprecated constructs in the language modes they’re obsolete in, and your suggestion elides some of those diagnostics in an effort to be less chatty. That goal is nice and something I’m usually in favor of, but is actually opposed to my goal in this case. I want people to know all the places where they’re using a deprecated feature. Any suggestion which boils down to “don’t warn on this even though it’s deprecated” misses that goal of mine.

Default-on warnings should diagnose only code which is very likely to be invalid/broken and needs to be changed. My contention is that code using a no-prototype function as if it was a no-arg prototyped function doesn’t meet that level of wrongness, and therefore we shouldn’t warn on it by default. Yes, such code would be improved by switching to void func(void);, but “can be improved” is not enough to be worth a default-on warning – especially since C2x is coming soon, and improves the code automatically.

Furthermore, saying that such code is “deprecated” feels kind of wrong, now that C2x has fixed it. Indeed, the current semantics are deprecated, but the new semantics for the same syntax are not. C2x has effectively “undeprecated” the syntax void func(); – so long as it’s being used as a no-arg function. There would, perhaps ironically, be a stronger case for emitting a warning on such declarations if C2x hadn’t made this change!

I think it’s important to warn on all deprecated uses because I don’t think we can rely on usage catching all of the issues. e.g.,

void func(); // In a header

void func() { } // In a source file, demonstrates the user intended to use void func(void);

You can still call func through inline assembly and pass it arguments without realizing it.

But, it’s always the case that you can do wrong things in inline asm. Even if the function does have a prototype. This seems unrelated and unfixable.

You can also use func() properly within your library test suite, but then users of your library accidentally misuse the interface in their code.

And we will then warn on those misuses in users’ code. That seems fine?

Also, it’s not clear how to handle cases like using the K&R type in a _Generic selection expression (so there’s no declaration involved, just the type name).

I think this is likely to be so rare that it’s not worth worrying about.

Rather than try to chase down answers to all the myriad of ways you can run into these signatures, I think it’s better to just say “spelling the deprecated type gets you a deprecation warning”. My thinking has been that -Wstrict-prototypes covers exactly the cases I think we need to cover, which is why I was thinking of rewording the diagnostic to be specific to the deprecation issue and then enabling that by default.

We don’t need to diagnose 100% of bad code for a warning diagnostic to be useful/good.

That’s why I don’t think changing the heuristics here gains us much. Additional diagnostics on top of the deprecation warning may be worthwhile, but I sort of think -fstrict-prototypes might (maybe) obviate a need for that work. From your three warning suggestions, in that mode: #1 becomes an error (invalid declaration), #2 becomes an error (invalid function call expression), and #3 becomes an error (invalid redeclaration). And there would be no diagnostics with the fourth case you list. So it does cover your use cases, but with errors instead of warnings (which could be a downside).

I don’t think a flag to change the semantics in older language modes is a solution. We cannot turn it on by default in older standards modes, and having projects go around enabling an extra compiler flag which creates a nonstandard dialect is not great either. But, we can emit warnings by default.

Is this really true? On powerpc64le, f is currently called with a parameter save area set up. After the C2X change, I expect behavior similar to C++ (no parameter save area). The parameter save area is somewhat misnamed, compilers can use it to spill non-parameters, too. Therefore its absence can lead to data corruption.

This is true according to the standard, but I think practice, implementers (at least in the POSIX camp, until recently) have avoided taking this liberty.

Yes, for this particular issue, treating char shm_open (); as a prototype declaration works. This is not surprising; the core autoconf checks should work with a C++ compiler these days (hence the #ifdef __cplusplus).

Default-on warnings should diagnose only code which is very likely to be invalid/broken and needs to be changed. My contention is that code using a no-prototype function as if it was a no-arg prototyped function doesn’t meet that level of wrongness, and therefore we shouldn’t warn on it by default. Yes, such code would be improved by switching to void func(void); , but “can be improved” is not enough to be worth a default-on warning – especially since C2x is coming soon, and improves the code automatically.

I strongly disagree. This is deprecated functionality. The whole reason we’re in the mess we’re in today is because we (and GCC) never diagnosed the deprecated functionality the way we should have. I’m wholly opposed to not diagnosing the deprecated interfaces by default in the language modes where they’re deprecated. That is the bar in Clang; we’ve failed to meet that bar for long enough, and this RFC is intended to address that specifically.

Furthermore, saying that such code is “deprecated” feels kind of wrong, now that C2x has fixed it.

Strong disagreement here as well. There’s no way to tell me “this feature is obsolescent in this language mode” is not a deprecated feature. Not everyone is updating their code to C2x. People are interested in staying at C99 for the time being but still don’t want to rely on deprecated functionality because they want to leave the door open to update to newer language standards in the future.

And we will then warn on those misuses in users’ code. That seems fine?

Not at all fine to me – as a library author, I don’t want my users to report this embarrassing bug to me; I want to know about the bug before I release my library to them.

Are we perhaps disagreeing because of the warning group itself? I was envisioning turning -Wstrict-prototype into a deprecation warning (perhaps it should also be placed under the -Wdeprecated group, which is a point I hadn’t thought of before). You seem to envision it as a “your code is functionally deficient” warning, which is fair because that’s sort of what it tries to be today. Maybe my RFC would make more sense or be more palatable if it was instead -Wdeprecated-declarations (or some new warning group) will now diagnose functions without prototypes by default in all C language modes, and the behavior of -Wstrict-prototypes is left untouched (or possibly improved)?

For reference, the ABI under discussion: http://cdn.openpowerfoundation.org/wp-content/uploads/resources/64-bit-ELF-V2-ABI-Specification/content/ch_preface.html

Relevant quote from that standard: “When the callee’s parameter list indicates that the caller must allocate the Parameter Save Area (because at least one parameter must be passed in memory or an ellipsis is present in the prototype), the callee may use the preallocated Parameter Save Area to save incoming parameters.”

This means neither void f() {} nor void f(void) {} are allowed to use the parameter save area. Given that the callee isn’t allowed to use the parameter save area, it doesn’t matter if the caller allocates it.

I guess if you had something like void f(); void g() { f(); } /*In another file*/ void f(int a, ...) {}, you could get memory corruption? But calling a function with the wrong number of parameters can cause memory corruption anyway.

People are interested in staying at C99 for the time being but still don’t want to rely on deprecated functionality because they want to leave the door open to update to newer language standards in the future.

I agree with that statement, and I think this is actually the key of my disagreement with the conclusion. IMO, the primary goal of emitting deprecation warnings is to dissuade people from writing code now that will fail in a new language version (or new library version in case of -Wdeprecated-declarations). We turn such deprecation warnings on by default in order to ease such migrations – even though they may not be indicating a current functional problem with your code.

As a thought experiment: pretend there was a situation where C V1 supports X, V2 deprecates X, and then V3 un-deprecates X (“oops, nevermind”). In such a case, I hope you’d agree, there’s no purpose served by introducing a deprecation warning for code using X, even when built for C V2, because we already know the decision was made not to remove X.

Of course, that’s not precisely the situation we’re in, since we have a semantics change, not a simple “un-deprecation”. Yet, the effect seems similar. In my view, there’s two separate purposes served by a strict-prototypes warning:

  1. Warn that you’re doing something which will be incompatible with C2x.
  2. Warn that you’re doing something which was probably unintended, but is not broken by C2x (declaring a prototype-less function instead of void function, without providing arguments.)

I think #1 very clearly meets the requirements for on-by-default “deprecation warning”, because it will break in C2x. I think #2 does not fit under the same criteria, because it will not break in C2x. So, to argue for #2 to be on-by-default seemingly requires some other rationale.

One rationale might be if code in situation #2 is so likely to indicate functionally broken code, that it’s worth a default warning (ala -Wincompatible-pointer-types). Another rationale might be that there’s so little code that hits situation #2, that it’s not worth the development cost for the compiler to distinguish it from #1. I don’t expect either of those are actually true, but if someone collected data demonstrating one, I think that could be convincing.

That said, I do think there’s a reasonable argument that #2 should be diagnosed in a warning group like -Wextra or -Wall – under the (weaker) rationale that the code is “probably unintended” – despite not likely being functionally broken now or in the future.

And we will then warn on those misuses in users’ code. That seems fine?

Not at all fine to me – as a library author, I don’t want my users to report this embarrassing bug to me; I want to know about the bug before I release my library to them.

Yes, by omitting the “void”, your library has made it easier for clients to write buggy code that passes undiagnosed by the compiler. Yet, the functional bug is on the part of the client calling the function incorrectly, not your code. But this is a good argument for adding the warning to a warning group that well-maintained libraries will be tested with.

2 Likes

As a thought experiment: pretend there was a situation where C V1 supports X, V2 deprecates X, and then V3 un-deprecates X (“oops, nevermind”). In such a case, I hope you’d agree, there’s no purpose served by introducing a deprecation warning for code using X, even when built for C V2, because we already know the decision was made not to remove X.

Of course, that’s not precisely the situation we’re in, since we have a semantics change, not a simple “un-deprecation”. Yet, the effect seems similar.

ANSI C (V1) supported X, C89 (V2) deprecated X in 1989, C2x (V6) “undeprecates” (after a fashion) X in 2023. There’s a lot of daylight between V2 and V6 (34 years worth). So the effects are similar, but with a lot more time for people to accidentally be using the deprecated code due to the lack of warning about it.

In my view, there’s two separate purposes served by a strict-prototypes warning:

  1. Warn that you’re doing something which will be incompatible with C2x.
  2. Warn that you’re doing something which was probably unintended, but is not broken by C2x (declaring a prototype-less function instead of void function, without providing arguments.)

I think #1 very clearly meets the requirements for on-by-default “deprecation warning”, because it will break in C2x.

Agreed.

I think #2 does not fit under the same criteria, because it will not break in C2x. So, to argue for #2 to be on-by-default seemingly requires some other rationale.

Agreed, but only for a strict prototypes warning. Not agreed for a general warning that something is deprecated, however. Deprecation warnings aren’t just “this may be incompatible in the future”, they’re often (and definitely in this case is) “there is a better way to do this today”.

One rationale might be if code in situation #2 is so likely to indicate functionally broken code, that it’s worth a default warning (ala -Wincompatible-pointer-types).

I think we’re in this situation, but we may disagree on what “broken code” means. To me, broken code also includes code that does not behave as the author intended it to. In the case of #2, I think the author expected the function to accept no arguments and the code does not behave the way they intended it to. There is anecdotal evidence that people run into this without realizing it though:

MinGW-w64 - for 32 and 64 bit Windows / Code / [r6638] /trunk/mingw-w64-libraries/winpthreads/include/pthread.h (line 404)
MinGW-w64 - for 32 and 64 bit Windows / Code / [r6638] /trunk/mingw-w64-libraries/winpthreads/src/thread.c (line 922)

The author clearly doesn’t expect anyone using this library interface to pass arguments, but that’s not the semantics of the function in reality. (This is a private library interface, and so perhaps not as compelling as public library interfaces, but it does demonstrate that library authors get this wrong.) To me, this represents broken code, but a less severe break than UB-inducing calls to code like this.

Another rationale might be that there’s so little code that hits situation #2, that it’s not worth the development cost for the compiler to distinguish it from #1. I don’t expect either of those are actually true, but if someone collected data demonstrating one, I think that could be convincing.

There’s extant code this will hit, for sure.

That said, I do think there’s a reasonable argument that #2 should be diagnosed in a warning group like -Wextra or -Wall – under the (weaker) rationale that the code is “probably unintended” – despite not likely being functionally broken now or in the future.

That’s an interesting idea and one that I think I’d be happy enough with.

Yes, by omitting the “void”, your library has made it easier for clients to write buggy code that passes undiagnosed by the compiler. Yet, the functional bug is on the part of the client calling the function incorrectly, not your code.

I believe there’s a bug in the library interface because the semantics of the signature do not match the intent of the author. There may also be an additional bug on the client side, especially if there is documentation that the library interface doesn’t accept arguments. But as an example, I would have a hard time blaming an inattentive user for the user code here:

// LibraryHeader.h
void setSomeGlobalState();
void clearSomeGlobalState();

// LibrarySource.c
void setSomeGlobalState() { GlobalState = true; }
void clearSomeGlobalState() { GlobalState = false; }

// UserCode.c
void whatever(void) {
  setSomeGlobalState(true);
  ...
  setSomeGlobalState(false);
}

But this is a good argument for adding the warning to a warning group that well-maintained libraries will be tested with.

Agreed.

Here’s a way forward that I think will be acceptable from everyone’s feedback (please correct me where you disagree):

Changing the behavior of -Wstrict-prototypes to warn on less cases means the warning is less powerful for people who want strict prototypes, but in order to make it palatable to be on by default or within -Wall, we’d need to change it to warn on less cases. So I think what I’m hearing is that we should leave -Wstrict-prototypes alone (leave it off by default, don’t change its behavior), but see the conclusion for a plot twist.

Instead, it sounds like we want two new, related warnings. One which diagnoses functions without a prototype that will change behavior in C2x. This will be on by default (should it be -Werror by default?). A second one which diagnoses functions without a prototype but don’t change behavior in C2x. This one will be off by default, but enabled by -Wall (and won’t be -Werror by default).

The only way to select which diagnostic a function without a prototype will generate is from the function definition. That’s the point at which we’ll know whether the user has an identifier list (broken by C2x) or not (takes no args, doesn’t change behavior in C2x). We will not base the decision to diagnose the declaration on the call sites where the function is called (that requires a CFG analysis and I don’t think is worth the effort for these diagnostics). However, there are other cases where no definition will exist:

void func(void (*fp)()) {
  extern void foo();
  ...
}

I can see arguments for either diagnostic in these kinds of circumstances, I would probably go with “don’t change behavior in C2x” warning to be conservative.

Because these two new diagnostics combined cover exactly the same cases as -Wstrict-prototypes, I think we can use that as the diagnostic group for the two new diagnostics. This way, when a user has already enabled -Wstrict-prototypes explicitly, they don’t get two diagnostics for the on-by-default diagnostic cases. If that’s a reasonable idea, that also helps nail down the diagnostic behavior of the examples I gave above.

Here are examples to demonstrate what I’m thinking (Compiler Explorer):

// Off by default warnings, enabled by -Wall
void other_func(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}
void other_func() {} // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}

void never_defined(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}

typedef void (*fp)(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}

void whatever(void) {
  extern void hoo_boy();  // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}
}

// On by default warnings (perhaps defaulted as errors)
void func(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C and changes behavior in C2x}}
void func(a, b) int a, b; {} // expected-warning {{this function declaration without a prototype is deprecated in all versions of C and changes behavior in C2x}}

Additionally, it sounds like there’s also appetite for -fstrict-prototypes which uses the C2x prototype rules in any C language mode. This can be implemented once we actually implement those strict prototype rules for C2x.

Does that seem like an acceptable path forward to folks?

Instead, it sounds like we want two new, related warnings. One which diagnoses functions without a prototype that will change behavior in C2x. This will be on by default (should it be -Werror by default?).

I think it probably should be on but not -Werror, by default. I wonder what this should be named…maybe something like “-Wstrict-prototypes-incompatible”? Or maybe “-Wdeprecated-non-prototype”.

A second one which diagnoses functions without a prototype but don’t change behavior in C2x. This one will be off by default, but enabled by -Wall (and won’t be -Werror by default).

Perhaps this message can remain directly under the “-Wstrict-prototypes” warning name? (-Wstrict-prototypes would then include the diagnostic group described above, and this diagnostic directly).

The only way to select which diagnostic a function without a prototype will generate is from the function definition. That’s the point at which we’ll know whether the user has an identifier list (broken by C2x) or not (takes no args, doesn’t change behavior in C2x). We will not base the decision to diagnose the declaration on the call sites where the function is called (that requires a CFG analysis and I don’t think is worth the effort for these diagnostics).

Definitely need a diagnostic for identifier lists on definitions. I’ve just noticed we don’t even warn about these at all right now if there’s a preceeding prototype, even in -Wstrict-prototypes. (Ugh!)

And I think we also should also diagnose callsites, to catch cases where users are passing args to a function which never intended to take arguments.

I’m not sure why you say this would require a CFG analysis? The way I’d imagine it to work is to diagnose a call if it:

  • has more than zero parameters, and
  • calls a non-prototype function type, and
  • the “broken in C2x” diagnostic was enabled at the declaration source-location.
    Then, emit a diagnostic, with a note pointing at the declaration.

That is, with default flags:

int f();

void f2() { f(); }
int f(a, b) int a, b; {} // expected-warning {{deprecated old-style function definitions will be removed in C2x}}

int g(); // expected-note {{non-prototype function defined here}}

void g2(void) {

g(5); // expected-warning {{passing arguments to a deprecated non-prototype function, which will be treated as a zero-argument function in C2x.}}

}

#pragma gcc diagnostic push
#pragma gcc diagnostic ignore "-Wstrict-prototypes"
int h();
#pragma gcc diagnostic pop
void h2(void) {
g(5); // no warning!
}

And passing -Wstrict-prototypes would get you a warning on int f(); and int g(); lines, as well.

Because these two new diagnostics combined cover exactly the same cases as -Wstrict-prototypes, I think we can use that as the diagnostic group for the two new diagnostics. This way, when a user has already enabled -Wstrict-prototypes explicitly, they don’t get two diagnostics for the on-by-default diagnostic cases. If that’s a reasonable idea, that also helps nail down the diagnostic behavior of the examples I gave above.

+1, modulo whether the latter diagnostic might stay directly in -Wstrict-prototypes.

Additionally, it sounds like there’s also appetite for -fstrict-prototypes which uses the C2x prototype rules in any C language mode. This can be implemented once we actually implement those strict prototype rules for C2x.

I’m not sure this is really going to be necessary. But it also doesn’t seem harmful, beyond just the “Yet Another Compilation Option” concern.

1 Like

That’s not true. Aside from call sites, we can diagnose on cases requiring compatibility between () and a function type with other than () or (void): That is, we can diagnose on redeclarations, pointer assignments/argument passing/function returns, relational/equality/ternary operators, and _Generic.

I think we should change the message to say “function type” instead of “function declaration”.

1 Like

I actually implemented a patch roughly along these lines a while back before this RFC happened. Unfortunately during review we got bogged down in discussions on the correct general direction for handling functions without prototypes in Clang and so I abandoned the patch.

1 Like

SGTM on the not -Werror by default. I think -Wdeprecated-non-prototype would work, or -Wdeprecated-non-prototype-changes-behavior if we wanted to have an obnoxiously long but precise name for it.

I think that would be reasonable, but would -Wstrict-prototypes then be added to -Wall?

FWIW, I had exactly that review in mind for that functionality once we figured out the correct path forward. Sorry for bogging your patch down, but as you can see, the decisions here are somewhat subtle.

@jyknight – do you view this as a third diagnostic group, or were you expecting this to be handled under one of the other two above? (My feeling is that this is a third diagnostic option.)

I was thinking about how we should handle a case like this:

// Header.h
void f(); // No prototype, no information about which usage is correct

// Source.c
void func(int i) {
  if (i % 2 == 0) f(); else f(1);
}

and my desire to not warn about the declaration of f() based on its usages in func() (and elsewhere in the TU). However, you’re right that we don’t need a CFG to care about what calls are reached, we can use the AST to see what ones are potentially called. I was more worried that we’d give a warning on f() because we later saw a call passing arguments to it, but it’s every bit as possible that the second call is correct and the issue is that the first call forgot to pass an argument. That said, keeping the diagnostic focused on the deprecation means that the diagnostic won’t be wrong in your suggested approach and I was more thinking about the diagnostic from the “your code is wrong” perspective there. So I think we’re in agreement that something like this approach could work for the call-site diagnostic.

But there’s still an issue:

We have no facilities (that I am aware of or can find) that will tell us whether a diagnostic is enabled at a given source location; this information is tracked within the diagnostics engine, not the AST. Once the diagnostic engine pops the diagnostic stack, all the information about the range is lost. (Also, this may get harder to maintain in the future if we add other suppression mechanisms as there have been a few attempts at a diagnostic suppression attribute and NOLINT comments, as examples.) So I’d prefer if this part was left as follow-up work rather than block on it. It seems like useful functionality, though the nature of this being the first time we’d have a diagnostic that depends on the state of the diagnostics engine at another point in compilation makes me think we should be cautious about usability.

I’d like to reach some closure on this. As best I can tell, it sounds like the path forward is:

  • Add -Wdeprecated-non-prototype that is on-by-default and warns about functions without a prototype that change behavior in C2x. Add it to the -Wstrict-prototypes diagnostic group.
  • Change -Wstrict-prototypes to diagnose functions without a prototype that don’t change behavior in C2x, it remains off-by-default but is automatically enabled by -pedantic as it’s still warning the user about a deprecation.
  • Add -Wstrict-calls-without-prototype that is on-by-default and warns about any call to a function without a prototype but is passed args, group it under -Wdeprecated-non-prototype.
  • Optionally, when enabling the C2x behavior, add -fstrict-prototypes to use the C2x prototype rules in any C language mode

The resulting behavior would be:

// Off by default warnings, enabled by -pedantic
void other_func(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}
void other_func() {} // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}

void never_defined(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}

typedef void (*fp)(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}

void whatever(void) {
  extern void hoo_boy();  // expected-warning {{this function declaration without a prototype is deprecated in all versions of C}}
}

// On by default warnings
void func(); // expected-warning {{this function declaration without a prototype is deprecated in all versions of C and changes behavior in C2x}}
void func(a, b) int a, b; {} // expected-warning {{this function declaration without a prototype is deprecated in all versions of C and changes behavior in C2x}}

void another(); // No warning on by default for this

int main(void) {
  another(1, 2); // expected-warning {{calling function 'another' with arguments when the function has no prototype}}
}

The latest proposal SGTM.

We have no facilities (that I am aware of or can find) that will tell us whether a diagnostic is enabled at a given source location; this information is tracked within the diagnostics engine, not the AST

I think DiagnosticsEngine::isIgnored(unsigned DiagID, SourceLocation Loc) already works for this? AFAIK we keep all valid diagnostic states for the whole compilation; the push/pop stack is separate from the state map DiagStatesByLoc.

Also, just to explicitly state another example of why decl-point-suppression might be good for users: if a system header contains a non-prototype function type (whose definition does in fact expect arguments), but system header warnings are disabled, should we emit -Wstrict-calls-without-prototype warnings for any with-argument calls from user code? My inclination is that we should not, for the same reasons we usually suppress system header warnings.

This also diagnoses with:

void func();
void func(int);

(and same for the reverse order) as part of -Wdeprecated-non-prototype (separately from the “calls” warning)?

Can we name that -Wstrict-uses-without-prototype so that it can encompass other cases like function pointer assignment?

Oh! I missed that when I was investigating; that looks very promising. I’ll see if I can use it, either in the initial work or a follow-up. Thank you!

I think it should, yes.

I think that’s a good idea!