Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2222,25 +2222,20 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
handles traversal of template args and qualifier. \
For explicit specializations ("template<> set<int> {...};"), \
we traverse template args here since there is no EID. */ \
if (const auto *ArgsWritten = D->getTemplateArgsAsWritten()) { \
assert(D->getTemplateSpecializationKind() != TSK_ImplicitInstantiation); \
if (D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \
TRY_TO(TraverseTemplateArgumentLocsHelper( \
ArgsWritten->getTemplateArgs(), ArgsWritten->NumTemplateArgs)); \
} \
} \
\
if (getDerived().shouldVisitTemplateInstantiations() || \
D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \
/* Traverse base definition for explicit specializations */ \
TRY_TO(Traverse##DECLKIND##Helper(D)); \
} else { \
if (D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \
const auto *ArgsWritten = D->getTemplateArgsAsWritten(); \
TRY_TO(TraverseTemplateArgumentLocsHelper( \
ArgsWritten->getTemplateArgs(), ArgsWritten->NumTemplateArgs)); \
} else if (!getDerived().shouldVisitTemplateInstantiations()) { \
/* Returning from here skips traversing the \
declaration context of the *TemplateSpecializationDecl \
(embedded in the DEF_TRAVERSE_DECL() macro) \
which contains the instantiated members of the template. */ \
return true; \
} \
\
/* Traverse base definition for explicit specializations */ \
TRY_TO(Traverse##DECLKIND##Helper(D)); \
})

DEF_TRAVERSE_TMPL_SPEC_DECL(Class, CXXRecord)
Expand Down
25 changes: 25 additions & 0 deletions clang/test/AST/pr198903.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_cc1 -ast-list %s | FileCheck -strict-whitespace %s

template <typename>
struct Tpl {
template <typename>
static int var;
};
// CHECK: Tpl
// CHECK-NEXT: Tpl::(anonymous)
// CHECK-NEXT: Tpl
// CHECK-NEXT: Tpl::var
// CHECK-NEXT: Tpl::(anonymous)
// CHECK-NEXT: Tpl::var

template <typename T>
template <typename>
int Tpl<T>::var;
// CHECK-NEXT: Tpl::var
// CHECK-NEXT: Tpl::(anonymous)
// CHECK-NEXT: Tpl::var
// CHECK-NEXT: T

int i = Tpl<int>::var<int>;
// CHECK-NEXT: i
// CHECK-NEXT: Tpl<int>::var
25 changes: 25 additions & 0 deletions clang/test/Analysis/pr169302.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core -verify %s

// expected-no-diagnostics

template <typename> struct S;

class Sp {
public:
template <bool> void M() {}
template <unsigned> struct I {
static void IM();
};
};

template <> struct S<Sp> {
using F = void (Sp::*)();
template <bool P> static constexpr F SpM = &Sp::template M<P>;
};

template <bool> constexpr S<Sp>::F S<Sp>::SpM;

template <unsigned X> void Sp::I<X>::IM() {
using Spec = S<Sp>;
typename Spec::F E = Spec::template SpM<true>;
}