[PATCH] D53456: [Sema] Do not show unused parameter warnings when body is skipped

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 19 15:42:06 PDT 2018


ilya-biryukov created this revision.
ilya-biryukov added reviewers: ioeric, sammccall.
Herald added a subscriber: arphaman.

Without the function body, we cannot determine is parameter was used.


Repository:
  rC Clang

https://reviews.llvm.org/D53456

Files:
  lib/Sema/SemaDecl.cpp
  test/Index/skipped-bodies-unused.cpp


Index: test/Index/skipped-bodies-unused.cpp
===================================================================
--- /dev/null
+++ test/Index/skipped-bodies-unused.cpp
@@ -0,0 +1,8 @@
+// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s -Wunused-parameter 2>&1 \
+// RUN: | FileCheck %s
+
+// No 'unused parameter' warnings should be shown when skipping the function bodies.
+inline int foo(int used, int unused) {
+    used = 100;
+}
+// CHECK-NOT: warning: unused parameter
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -13037,7 +13037,7 @@
 
     if (!FD->isInvalidDecl()) {
       // Don't diagnose unused parameters of defaulted or deleted functions.
-      if (!FD->isDeleted() && !FD->isDefaulted())
+      if (!FD->isDeleted() && !FD->isDefaulted() && !FD->hasSkippedBody())
         DiagnoseUnusedParameters(FD->parameters());
       DiagnoseSizeOfParametersAndReturnValue(FD->parameters(),
                                              FD->getReturnType(), FD);
@@ -13132,7 +13132,8 @@
     assert(MD == getCurMethodDecl() && "Method parsing confused");
     MD->setBody(Body);
     if (!MD->isInvalidDecl()) {
-      DiagnoseUnusedParameters(MD->parameters());
+      if (!MD->hasSkippedBody())
+        DiagnoseUnusedParameters(MD->parameters());
       DiagnoseSizeOfParametersAndReturnValue(MD->parameters(),
                                              MD->getReturnType(), MD);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53456.170268.patch
Type: text/x-patch
Size: 1534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181019/e413e8ca/attachment.bin>


More information about the cfe-commits mailing list