aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorOleksandr T. <oleksandr.tarasiuk@outlook.com>2025-04-08 23:21:53 +0300
committerGitHub <noreply@github.com>2025-04-08 23:21:53 +0300
commit9f463056e6dd5ff94d35f8cc1f4aa4ecc87fa61d (patch)
tree582109298a003639a76b6857650cc33b4b8ea5f7 /clang/lib/Sema/SemaDecl.cpp
parent156e2532edeaea9a60c37c041e8059fc5693122f (diff)
downloadllvm-9f463056e6dd5ff94d35f8cc1f4aa4ecc87fa61d.zip
llvm-9f463056e6dd5ff94d35f8cc1f4aa4ecc87fa61d.tar.gz
llvm-9f463056e6dd5ff94d35f8cc1f4aa4ecc87fa61d.tar.bz2
[Clang] add ext warning for missing return in 'main' for C89 mode (#134617)
Fixes #21650 --- Clang currently inserts an implicit `return 0;` in `main()` when compiling in `C89` mode, even though the `C89` standard doesn't require this behavior. This patch changes that behavior by emitting a warning instead of silently inserting the implicit return under `-pedantic`.
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 540f5f2..1c30458 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16232,7 +16232,12 @@ 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>())
+ // Clang implicitly returns 0 in C89 mode, but that's considered an
+ // extension. The check is necessary to ensure the expected extension
+ // warning is emitted in C89 mode.
+ if ((FD->hasImplicitReturnZero() &&
+ (getLangOpts().CPlusPlus || getLangOpts().C99 || !FD->isMain())) ||
+ FD->hasAttr<NakedAttr>())
WP.disableCheckFallThrough();
// MSVC permits the use of pure specifier (=0) on function definition,