r207672 - -Wunused-parameter: Don't fire on defaulted or deleted functions

Reid Kleckner reid at kleckner.net
Wed Apr 30 09:31:29 PDT 2014


Author: rnk
Date: Wed Apr 30 11:31:28 2014
New Revision: 207672

URL: http://llvm.org/viewvc/llvm-project?rev=207672&view=rev
Log:
-Wunused-parameter: Don't fire on defaulted or deleted functions

Patch by Dinesh Dwivedi!

Differential Revision: http://reviews.llvm.org/D3376

Added:
    cfe/trunk/test/SemaCXX/cxx11-unused.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=207672&r1=207671&r2=207672&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr 30 11:31:28 2014
@@ -9921,7 +9921,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
       Diag(FD->getLocation(), diag::warn_pure_function_definition);
 
     if (!FD->isInvalidDecl()) {
-      DiagnoseUnusedParameters(FD->param_begin(), FD->param_end());
+      // Don't diagnose unused parameters of defaulted or deleted functions.
+      if (Body)
+        DiagnoseUnusedParameters(FD->param_begin(), FD->param_end());
       DiagnoseSizeOfParametersAndReturnValue(FD->param_begin(), FD->param_end(),
                                              FD->getReturnType(), FD);
 

Added: cfe/trunk/test/SemaCXX/cxx11-unused.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-unused.cpp?rev=207672&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx11-unused.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx11-unused.cpp Wed Apr 30 11:31:28 2014
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s -Wunused-parameter
+
+// PR19303 : Make sure we don't get a unused expression warning for deleted and
+// defaulted functions
+
+// expected-no-diagnostics
+
+class A {
+public:
+  int x;
+  A() = default;
+  ~A() = default;
+  A(const A &other) = delete;
+
+  template <typename T>
+  void SetX(T x) {
+    this->x = x;
+  };
+
+  void SetX1(int x);
+};
+
+template <>
+void A::SetX(A x) = delete;
+
+class B {
+public:
+  B() = default;
+  ~B() = default;
+  B(const B &other);
+};
+
+B::B(const B &other) = default;





More information about the cfe-commits mailing list