[PATCH] D121328: Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static"""
David Blaikie via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 24 10:53:08 PDT 2022
dblaikie updated this revision to Diff 417989.
dblaikie added a comment.
Add regression test for the -Wnon-c-typedef-for-linkage issue
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121328/new/
https://reviews.llvm.org/D121328
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/anonymous-struct.cpp
clang/test/SemaCXX/warn-missing-prototypes.cpp
Index: clang/test/SemaCXX/warn-missing-prototypes.cpp
===================================================================
--- clang/test/SemaCXX/warn-missing-prototypes.cpp
+++ clang/test/SemaCXX/warn-missing-prototypes.cpp
@@ -44,3 +44,16 @@
extern void k() {} // expected-warning {{no previous prototype for function 'k'}}
// expected-note at -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;
+}
Index: clang/test/SemaCXX/anonymous-struct.cpp
===================================================================
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -183,3 +183,9 @@
void memcpy(); // expected-note {{due to this member}}
} A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
}
+namespace inline_defined_static_member {
+typedef struct { // expected-warning {{anonymous non-C-compatible type}}
+ static void f() { // expected-note {{due to this member}}
+ }
+} A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14207,6 +14207,9 @@
if (isa<CXXMethodDecl>(FD))
return false;
+ if (!FD->isExternallyVisible())
+ return false;
+
// Don't warn about 'main'.
if (isa<TranslationUnitDecl>(FD->getDeclContext()->getRedeclContext()))
if (IdentifierInfo *II = FD->getIdentifier())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121328.417989.patch
Type: text/x-patch
Size: 1903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220324/afdfbe96/attachment.bin>
More information about the cfe-commits
mailing list