[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 14 05:14:02 PDT 2022


aaron.ballman added a comment.

In D122983#3450177 <https://reviews.llvm.org/D122983#3450177>, @rsmith wrote:

> It seems surprising to me for the diagnostic to change from warn-by-default to error-by-default when changing from C99 to C11, given that the language rule did not change between C99 and C11 (as a Clang user, when changing my `-std=` flag, I don't want other changes to come in that are unrelated to the language mode change I requested).

FWIW, that's the approach I originally considered. I eventually discarded it as being likely too disruptive for users (with risk of pushing some people to not upgrade to Clang 15).

This situation is a somewhat unique one. C89 supported this feature and it was not obsolescent in that revision of the standard. C99 removed the feature outright. (The same thing happened to implicit int.) Because there was no deprecation period, people got caught off guard and so compilers made it a warning in C99 that also triggered in C89. As best I can tell, this is the first time the severity question has been revisited. The reason I took the approach I did is because of the lack of deprecation period and the somewhat common user practice of using an effectively-C89 code base with some C99 features (most often: ability to mix decls + code, `//` comments, and `long long` support -- aka, what MSVC considered "C" to be for many, many years).

> I think we should just make this an error by default in C99 onwards; if we're happy promoting this from warning-by-default to error-by-default for the folks using `-std=c11` and later (and I think we are), then we should be happy doing the same for the `-std=c99` folks too -- especially given that C17 is the default everywhere other than on PS4.

I see where you're coming from, but I don't think it's practical. We've given users this as a warning in C99 and later for a *long* time (since Clang 2.6 from 2009), so I anticipate an error breaking some amount of code for people passing `-std=c99` explicitly. We do still run the risk of breaking people who are on C11 or C17 (particularly, given it's the default when no `-std=` is provided), but that feels like a more manageable risk. Those folks are clearly interested in upgrading language modes that I don't think apply to folks specifying C99 specifically (now that it's 20+ years old).

tl;dr: I think the current approach strikes a good balance between pushing people to improve their code and giving them a reasonable upgrade path through the language standards.


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

https://reviews.llvm.org/D122983



More information about the cfe-commits mailing list