Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly...
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 1 Feb 2022 01:32:31 +0000 (17:32 -0800)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 1 Feb 2022 01:34:51 +0000 (17:34 -0800)
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.

clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/warn-missing-prototypes.cpp

index e747ffc..cbd9df4 100644 (file)
@@ -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;
index e8637e5..2880514 100644 (file)
@@ -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;
+}