This revision was automatically updated to reflect the committed changes.
Closed by commit rL271199: Fix a wrong check in misc-unused-using-decls
(authored by hokein).
Changed prior to commit:
http://reviews.llvm.org/D20666?vs=58576=58937#toc
Repository:
rL LLVM
http://reviews.llvm.org/D20666
Files:
clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -18,20 +18,10 @@
namespace tidy {
namespace misc {
-// A function that helps to tell whether a TargetDecl will be checked.
-// We only check a TargetDecl if :
-// * The corresponding UsingDecl is not defined in macros or in class
-// definitions.
-// * Only variable, function and class types are considered.
+// A function that helps to tell whether a TargetDecl in a UsingDecl will be
+// checked. Only variable, function, function template, class template and
class
+// are considered.
static bool ShouldCheckDecl(const Decl *TargetDecl) {
- // Ignores using-declarations defined in macros.
- if (TargetDecl->getLocation().isMacroID())
-return false;
-
- // Ignores using-declarations defined in class definition.
- if (isa(TargetDecl->getDeclContext()))
-return false;
-
return isa(TargetDecl) || isa(TargetDecl) ||
isa(TargetDecl) || isa(TargetDecl) ||
isa(TargetDecl);
@@ -49,6 +39,14 @@
void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult ) {
if (const auto *Using = Result.Nodes.getNodeAs("using")) {
+// Ignores using-declarations defined in macros.
+if (Using->getLocation().isMacroID())
+ return ;
+
+// Ignores using-declarations defined in class definition.
+if (isa(Using->getDeclContext()))
+ return ;
+
UsingDeclContext Context(Using);
Context.UsingDeclRange = CharSourceRange::getCharRange(
Using->getLocStart(),
Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
@@ -33,6 +33,7 @@
template int UsedInTemplateFunc() { return 1; }
void OverloadFunc(int);
void OverloadFunc(double);
+int FuncUsedByUsingDeclInMacro() { return 1; }
class ostream {
public:
@@ -93,6 +94,11 @@
DEFINE_INT(test);
#undef DEFIND_INT
+#define USING_FUNC \
+ using n::FuncUsedByUsingDeclInMacro;
+USING_FUNC
+#undef USING_FUNC
+
// - Usages -
void f(B b);
void g() {
Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -18,20 +18,10 @@
namespace tidy {
namespace misc {
-// A function that helps to tell whether a TargetDecl will be checked.
-// We only check a TargetDecl if :
-// * The corresponding UsingDecl is not defined in macros or in class
-// definitions.
-// * Only variable, function and class types are considered.
+// A function that helps to tell whether a TargetDecl in a UsingDecl will be
+// checked. Only variable, function, function template, class template and class
+// are considered.
static bool ShouldCheckDecl(const Decl *TargetDecl) {
- // Ignores using-declarations defined in macros.
- if (TargetDecl->getLocation().isMacroID())
-return false;
-
- // Ignores using-declarations defined in class definition.
- if (isa(TargetDecl->getDeclContext()))
-return false;
-
return isa(TargetDecl) || isa(TargetDecl) ||
isa(TargetDecl) || isa(TargetDecl) ||
isa(TargetDecl);
@@ -49,6 +39,14 @@
void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult ) {
if (const auto *Using = Result.Nodes.getNodeAs("using")) {
+// Ignores using-declarations defined in macros.
+if (Using->getLocation().isMacroID())
+ return ;
+
+// Ignores using-declarations defined in class definition.
+if (isa(Using->getDeclContext()))
+ return ;
+
UsingDeclContext Context(Using);
Context.UsingDeclRange = CharSourceRange::getCharRange(
Using->getLocStart(),
Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
@@ -33,6 +33,7 @@
template int UsedInTemplateFunc() { return 1; }
void OverloadFunc(int);
void OverloadFunc(double);