Author: David Blaikie Date: 2022-01-31T17:34:51-08:00 New Revision: 275c56226d7fbd6a4d554807374f78d323aa0c1c
URL: https://github.com/llvm/llvm-project/commit/275c56226d7fbd6a4d554807374f78d323aa0c1c DIFF: https://github.com/llvm/llvm-project/commit/275c56226d7fbd6a4d554807374f78d323aa0c1c.diff LOG: Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static" Some functions can end up non-externally visible despite not being declared "static" or in an unnamed namespace in C++ - such as by having parameters that are of non-external types. Such functions aren't mistakenly intended to be defining some function that needs a declaration. They could be maybe more legible (except for the `operator new` example) with an explicit static, but that's a stylistic thing outside what should be addressed by a warning. Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/SemaCXX/warn-missing-prototypes.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e747ffc6f2ac1..cbd9df4d6a7b7 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14196,6 +14196,9 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, if (!FD->isGlobal()) return false; + if (!FD->isExternallyVisible()) + return false; + // Don't warn about C++ member functions. if (isa<CXXMethodDecl>(FD)) return false; diff --git a/clang/test/SemaCXX/warn-missing-prototypes.cpp b/clang/test/SemaCXX/warn-missing-prototypes.cpp index e8637e5a90eab..2880514ee02b7 100644 --- a/clang/test/SemaCXX/warn-missing-prototypes.cpp +++ b/clang/test/SemaCXX/warn-missing-prototypes.cpp @@ -44,3 +44,16 @@ void j() = delete; extern void k() {} // expected-warning {{no previous prototype for function 'k'}} // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}} // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{.*}}-[[@LINE-2]]:{{.*}}}:"{{.*}}" + +namespace { +struct anon { }; +} + +// No warning because this has internal linkage despite not being declared +// explicitly 'static', owing to the internal linkage parameter. +void l(anon) { +} + +void *operator new(decltype(sizeof(3)) size, const anon &) throw() { + return nullptr; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits