summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBolshakov <bolsh.andrey@yandex.ru>2022-07-22 17:03:33 +0300
committerKim Gräsman <kim.grasman@gmail.com>2022-07-23 10:31:48 +0200
commit57b812bf355cc2db316efcb3fce36dfd08825a04 (patch)
treed109c7e698b5367b8dcdbb80865d6cfcee106732
parentb46a96e5a646fc684c8eed95eb63f4e6edc9d679 (diff)
Report C++20 concept declaration use
-rw-r--r--iwyu.cc10
-rw-r--r--tests/cxx/concept-direct.h10
-rw-r--r--tests/cxx/concept-indirect.h11
-rw-r--r--tests/cxx/concept.cc30
4 files changed, 61 insertions, 0 deletions
diff --git a/iwyu.cc b/iwyu.cc
index 478bcfc..dcf7b58 100644
--- a/iwyu.cc
+++ b/iwyu.cc
@@ -124,6 +124,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprConcepts.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/OperationKinds.h"
#include "clang/AST/RecursiveASTVisitor.h"
@@ -163,6 +164,7 @@ using clang::CallExpr;
using clang::ClassTemplateDecl;
using clang::ClassTemplateSpecializationDecl;
using clang::CompilerInstance;
+using clang::ConceptSpecializationExpr;
using clang::ConstructorUsingShadowDecl;
using clang::Decl;
using clang::DeclContext;
@@ -4005,6 +4007,14 @@ class IwyuAstConsumer
return Base::VisitUnaryExprOrTypeTraitExpr(expr);
}
+ bool VisitConceptSpecializationExpr(ConceptSpecializationExpr* expr) {
+ if (CanIgnoreCurrentASTNode())
+ return true;
+ ReportDeclUse(CurrentLoc(), expr->getNamedConcept());
+ // TODO(bolshakov): analyze type parameter usage.
+ return Base::VisitConceptSpecializationExpr(expr);
+ }
+
// --- Visitors of types derived from clang::Type.
bool VisitTypedefType(clang::TypedefType* type) {
diff --git a/tests/cxx/concept-direct.h b/tests/cxx/concept-direct.h
new file mode 100644
index 0000000..4c8a707
--- /dev/null
+++ b/tests/cxx/concept-direct.h
@@ -0,0 +1,10 @@
+//===--- concept-direct.h - test input file for iwyu ----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "tests/cxx/concept-indirect.h"
diff --git a/tests/cxx/concept-indirect.h b/tests/cxx/concept-indirect.h
new file mode 100644
index 0000000..d261003
--- /dev/null
+++ b/tests/cxx/concept-indirect.h
@@ -0,0 +1,11 @@
+//===--- concept-indirect.h - test input file for iwyu --------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+template <typename>
+concept Concept = true;
diff --git a/tests/cxx/concept.cc b/tests/cxx/concept.cc
new file mode 100644
index 0000000..f20a3e6
--- /dev/null
+++ b/tests/cxx/concept.cc
@@ -0,0 +1,30 @@
+//===--- concept.cc - test input file for iwyu ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// IWYU_ARGS: -I . --std=c++20
+
+// Tests C++20 concepts usage reporting.
+
+#include "tests/cxx/concept-direct.h"
+
+// IWYU: Concept is...*concept-indirect.h
+constexpr bool b = Concept<int>;
+
+/**** IWYU_SUMMARY
+
+tests/cxx/concept.cc should add these lines:
+#include "tests/cxx/concept-indirect.h"
+
+tests/cxx/concept.cc should remove these lines:
+- #include "tests/cxx/concept-direct.h" // lines XX-XX
+
+The full include-list for tests/cxx/concept.cc:
+#include "tests/cxx/concept-indirect.h" // for Concept
+
+***** IWYU_SUMMARY */