]> granicus.if.org Git - clang/commitdiff
-Wunused-parameter: Don't fire on defaulted or deleted functions
authorReid Kleckner <reid@kleckner.net>
Wed, 30 Apr 2014 16:31:28 +0000 (16:31 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 30 Apr 2014 16:31:28 +0000 (16:31 +0000)
Patch by Dinesh Dwivedi!

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207672 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/cxx11-unused.cpp [new file with mode: 0644]

index 420842108073125fffc0b1f3f3e24c50ea9dfc48..e9c3c39b132389145d6c9ef080f698c5c09ffd53 100644 (file)
@@ -9921,7 +9921,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
       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);
 
diff --git a/test/SemaCXX/cxx11-unused.cpp b/test/SemaCXX/cxx11-unused.cpp
new file mode 100644 (file)
index 0000000..1e25bd5
--- /dev/null
@@ -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;