dblaikie created this revision.
dblaikie added reviewers: aaron.ballman, rsmith, denik, deansturtevant.
Herald added a project: All.
dblaikie requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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 275c56226d7fbd6a4d554807374f78d323aa0c1c 
<https://reviews.llvm.org/rG275c56226d7fbd6a4d554807374f78d323aa0c1c> - once we 
figure
out what to do about the change in behavior for -Wnon-c-typedef-for-linkage
(this reverts the revert commit 85ee1d3ca1d06b6bd3477515b8d0c72c8df7c069 
<https://reviews.llvm.org/rG85ee1d3ca1d06b6bd3477515b8d0c72c8df7c069>)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121328

Files:
  clang/lib/Sema/SemaDecl.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@-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/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14210,6 +14210,9 @@
   if (!FD->isGlobal())
     return false;
 
+  if (!FD->isExternallyVisible())
+    return false;
+
   // Don't warn about C++ member functions.
   if (isa<CXXMethodDecl>(FD))
     return false;


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@-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/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14210,6 +14210,9 @@
   if (!FD->isGlobal())
     return false;
 
+  if (!FD->isExternallyVisible())
+    return false;
+
   // Don't warn about C++ member functions.
   if (isa<CXXMethodDecl>(FD))
     return false;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to