Skip to content

Commit 275c562

Browse files
committed
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.
1 parent d329dfd commit 275c562

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14196,6 +14196,9 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
1419614196
if (!FD->isGlobal())
1419714197
return false;
1419814198

14199+
if (!FD->isExternallyVisible())
14200+
return false;
14201+
1419914202
// Don't warn about C++ member functions.
1420014203
if (isa<CXXMethodDecl>(FD))
1420114204
return false;

clang/test/SemaCXX/warn-missing-prototypes.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,16 @@ void j() = delete;
4444
extern void k() {} // expected-warning {{no previous prototype for function 'k'}}
4545
// expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
4646
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{.*}}-[[@LINE-2]]:{{.*}}}:"{{.*}}"
47+
48+
namespace {
49+
struct anon { };
50+
}
51+
52+
// No warning because this has internal linkage despite not being declared
53+
// explicitly 'static', owing to the internal linkage parameter.
54+
void l(anon) {
55+
}
56+
57+
void *operator new(decltype(sizeof(3)) size, const anon &) throw() {
58+
return nullptr;
59+
}

0 commit comments

Comments
 (0)