Skip to content

Commit 809019f

Browse files
committed
Skip TraverseExplicitInstantiationDecl
1 parent f467a98 commit 809019f

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎cpp2rust/converter/converter.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
503503
return true;
504504
}
505505

506+
bool TraverseExplicitInstantiationDecl(clang::ExplicitInstantiationDecl *) {
507+
return true;
508+
}
509+
506510
virtual bool
507511
VisitCXXStdInitializerListExpr(clang::CXXStdInitializerListExpr *expr);
508512

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,14 @@ bool IsCodeUnitStringLiteral(const clang::StringLiteral *expr) {
265265
bool IsUserDefinedDecl(const clang::Decl *decl) {
266266
const auto &ctx = decl->getASTContext();
267267
const auto &src_mgr = ctx.getSourceManager();
268-
const auto src_loc = decl->getLocation();
268+
auto src_loc = decl->getLocation();
269+
if (auto *spec = clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl);
270+
spec && (spec->getSpecializationKind() ==
271+
clang::TSK_ExplicitInstantiationDeclaration ||
272+
spec->getSpecializationKind() ==
273+
clang::TSK_ExplicitInstantiationDefinition)) {
274+
src_loc = spec->getSpecializedTemplate()->getLocation();
275+
}
269276
return !decl->getBeginLoc().isInvalid() && !decl->isImplicit() &&
270277
!src_mgr.isInSystemHeader(src_loc) &&
271278
!src_mgr.isInSystemMacro(src_loc);

‎tests/unit/class_templates.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,20 @@ template <typename T> struct Outer {
3939
Inner<int> with(int n) const { return Inner<int>{v, n}; }
4040
};
4141

42+
struct Elem {
43+
int i;
44+
};
45+
46+
template class std::vector<Elem>;
47+
48+
template struct Boxed<short>;
49+
4250
int main() {
51+
std::vector<Elem> ev;
52+
ev.push_back(Elem{2});
53+
assert(ev[0].i == 2);
54+
assert(Boxed<short>::twice(2) == 4);
55+
4356
Outer<int> oi{3};
4457
assert(oi.with(4).sum() == 7);
4558
Outer<long> ol{5};

0 commit comments

Comments
 (0)