Skip to content

Commit 34b9b1e

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. This reapplies 275c562 - once we figure out what to do about the change in behavior for -Wnon-c-typedef-for-linkage (this reverts the revert commit 85ee1d3) Differential Revision: https://reviews.llvm.org/D121328
1 parent a5032b2 commit 34b9b1e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14233,6 +14233,11 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
1423314233
if (FD->isDeleted())
1423414234
return false;
1423514235

14236+
// Don't warn on implicitly local functions (such as having local-typed
14237+
// parameters).
14238+
if (!FD->isExternallyVisible())
14239+
return false;
14240+
1423614241
for (const FunctionDecl *Prev = FD->getPreviousDecl();
1423714242
Prev; Prev = Prev->getPreviousDecl()) {
1423814243
// Ignore any declarations that occur in function or method

clang/test/SemaCXX/anonymous-struct.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,9 @@ namespace BuiltinName {
183183
void memcpy(); // expected-note {{due to this member}}
184184
} A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
185185
}
186+
namespace inline_defined_static_member {
187+
typedef struct { // expected-warning {{anonymous non-C-compatible type}}
188+
static void f() { // expected-note {{due to this member}}
189+
}
190+
} A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
191+
}

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)