[clang-tools-extra] r303552 - [clang-tidy] readability-redundant-declaration false positive for defaulted function

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 06:58:57 PDT 2017


Author: alexfh
Date: Mon May 22 08:58:57 2017
New Revision: 303552

URL: http://llvm.org/viewvc/llvm-project?rev=303552&view=rev
Log:
[clang-tidy] readability-redundant-declaration false positive for defaulted function

Summary:
```
template <class T>
struct C {
  C();
};

template <class T>
C<T>::C() = default;
```

Causes a readability-redundant-declaration diagnostic. This is caused by `isDefinition` not matching defaulted functions.

Reviewers: alexfh, danielmarjamaki

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Patch by Florian Gross!
Differential Revision: https://reviews.llvm.org/D33358

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp?rev=303552&r1=303551&r2=303552&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp Mon May 22 08:58:57 2017
@@ -19,11 +19,12 @@ namespace tidy {
 namespace readability {
 
 void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
-  auto UnlessDefinition = unless(isDefinition());
-  Finder->addMatcher(namedDecl(anyOf(varDecl(UnlessDefinition),
-                                     functionDecl(UnlessDefinition)))
-                         .bind("Decl"),
-                     this);
+  Finder->addMatcher(
+      namedDecl(
+          anyOf(varDecl(unless(isDefinition())),
+                functionDecl(unless(anyOf(isDefinition(), isDefaulted())))))
+          .bind("Decl"),
+      this);
 }
 
 void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) {

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp?rev=303552&r1=303551&r2=303552&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp Mon May 22 08:58:57 2017
@@ -34,3 +34,11 @@ struct C {
   static int I;
 };
 int C::I;
+
+template <class T>
+struct C2 {
+  C2();
+};
+
+template <class T>
+C2<T>::C2() = default;




More information about the cfe-commits mailing list