diff options
| author | Alex Lorenz <arphaman@gmail.com> | 2016-12-07 10:52:18 +0000 |
|---|---|---|
| committer | Alex Lorenz <arphaman@gmail.com> | 2016-12-07 10:52:18 +0000 |
| commit | 840f8df67759b6893b6e58d2eb08124cb5822525 (patch) | |
| tree | 2a274e96cee6ac5da2847e68f735307e36e99baa /clang/lib/Sema/SemaDecl.cpp | |
| parent | 32d5aedd5be8e7f031525af31208d7ea8905945e (diff) | |
| download | bcm5719-llvm-840f8df67759b6893b6e58d2eb08124cb5822525.tar.gz bcm5719-llvm-840f8df67759b6893b6e58d2eb08124cb5822525.zip | |
Implement the -Wstrict-prototypes warning
This commit fixes PR20796. It implements the C only -Wstrict-prototypes warning.
Clang now emits a warning for function declarations which have no parameters
specified and for K&R function definitions with more than 0 parameters that are
not preceded by a previous prototype declaration.
The patch was originally submitted by Paul Titei!
rdar://15060615
Differential Revision: https://reviews.llvm.org/D16533
llvm-svn: 288896
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 984a14ad50d..1650a11222c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11878,6 +11878,21 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, << FixItHint::CreateInsertion(FTL.getRParenLoc(), "void"); } } + + // GNU warning -Wstrict-prototypes + // Warn if K&R function is defined without a previous declaration. + // This warning is issued only if the definition itself does not provide + // a prototype. Only K&R definitions do not provide a prototype. + // An empty list in a function declarator that is part of a definition + // of that function specifies that the function has no parameters + // (C99 6.7.5.3p14) + if (!FD->hasWrittenPrototype() && FD->getNumParams() > 0 && + !LangOpts.CPlusPlus) { + TypeSourceInfo *TI = FD->getTypeSourceInfo(); + TypeLoc TL = TI->getTypeLoc(); + FunctionTypeLoc FTL = TL.castAs<FunctionTypeLoc>(); + Diag(FTL.getLParenLoc(), diag::warn_strict_prototypes) << 1; + } } if (auto *MD = dyn_cast<CXXMethodDecl>(FD)) { |

