Need to use function "getAsCXXRecordDecl" of ASTMatchFinder.cpp in a clang-tidy check
Cong Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 10 09:27:43 PST 2016
Hi Richard,
You are right. Actually I just need to consider the cases that there are
full instantiations of the primary template. I have changed the strategy
and not use that function.
Thanks a lot!
Cong
On Wed, Feb 10, 2016 at 2:17 AM, Richard Smith <richard at metafoo.co.uk>
wrote:
> On Tue, Feb 9, 2016 at 4:15 PM, Cong Liu <congliu at 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160210/974e5e27/attachment.html>
More information about the cfe-commits
mailing list