diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-03-31 16:35:03 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-03-31 16:35:03 +0000 |
commit | 8499f3f5ff8d5f95ece8047780030a3daad1b6fa (patch) | |
tree | adfe701db4d6f289f3c9408a8b7441065c3a6889 /lib/Sema/SemaDecl.cpp | |
parent | 17f689f7f805be86bcafe0a8ecdef14269cb6442 (diff) |
Implement -Wmissing-prototypes. Fixes PR3911.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68110 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index be9a0e24d1..584d2b11f9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2741,6 +2741,28 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { diag::err_func_def_incomplete_result)) FD->setInvalidDecl(); + // GNU warning -Wmissing-prototypes: + // Warn if a global function is defined without a previous + // prototype declaration. This warning is issued even if the + // definition itself provides a prototype. The aim is to detect + // global functions that fail to be declared in header files. + if (!FD->isInvalidDecl() && FD->isGlobal() && !isa<CXXMethodDecl>(FD)) { + bool MissingPrototype = true; + for (const FunctionDecl *Prev = FD->getPreviousDeclaration(); + Prev; Prev = Prev->getPreviousDeclaration()) { + // Ignore any declarations that occur in function or method + // scope, because they aren't visible from the header. + if (Prev->getDeclContext()->isFunctionOrMethod()) + continue; + + MissingPrototype = !Prev->getType()->isFunctionProtoType(); + break; + } + + if (MissingPrototype) + Diag(FD->getLocation(), diag::warn_missing_prototype) << FD; + } + PushDeclContext(FnBodyScope, FD); // Check the validity of our function parameters |