On Tue, Feb 9, 2016 at 4:15 PM, Cong Liu <cong...@google.com> wrote: > Hi Richard, > > Thank you for your reply. Yes, the case I need to deal with is like what you > said: >> >> If you want to make the assumption that the primary template will be >> used for an unknown specialization, you'll need something like that >> function in ASTMatchFinder. > > > For example, > > template <typename T> > struct Base {}; > template <typename T> > struct Derived : Base<T>{}; > > Derived<int> T1; > > In this case, I need to firstly get the CXXBaseSpecifier from line 4, then > get the QualType of primary template (Base<T>), then get its declaration. > For this case, that function in ASTMatchFinder works but > Type::getAsCXXRecordDecl does not. > > So, what do you suggest?
Using that may not be correct when analysing virtual function overrides. Consider this: template<typename T> struct Base { virtual void f(T); }; template<> struct Base<void> { virtual void f(); }; template<typename T, bool = is_same<T, void>::value> struct Derived : Base<T> { virtual void f(); }; template<typename T> struct Derived<T, false> : Base<T> { virtual void f(T); }; Here, it would be wrong to report that the Derived primary template fails to override a virtual function from the Base primary template, as the Derived primary template is actually only ever used when T == void, and there's a specialization of the Base template for that case. I have no idea whether that's acceptable for your check. In principle, I'm fine with us moving the functionality in ASTMatchFinder (that I recently renamed to getAsCXXRecordDeclOrPrimaryTemplate to better express its purpose) to somewhere more central, but my concern is that most uses of it will in fact be subtle bugs. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits