[clang] [Clang] add ext warning for missing return in 'main' for C89 mode (PR #134617)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 7 10:42:40 PDT 2025
================
@@ -16232,7 +16232,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
// If the function implicitly returns zero (like 'main') or is naked,
// don't complain about missing return statements.
- if (FD->hasImplicitReturnZero() || FD->hasAttr<NakedAttr>())
+ if ((FD->hasImplicitReturnZero() &&
+ (getLangOpts().CPlusPlus || getLangOpts().C99 || !FD->isMain())) ||
----------------
AaronBallman wrote:
Oh I see what's going on, thank you for the explanation. Then I think all that's needed here is a comment saying something along the lines of: Clang implicitly returns 0 in C89 mode, but that's an extension, so we need to perform the check in that case to ensure we emit the expected extension warning in C89 mode.
https://github.com/llvm/llvm-project/pull/134617
More information about the cfe-commits
mailing list