[cfe-dev] class template methods

Reid Kleckner rnk at google.com
Mon May 4 11:00:35 PDT 2015


On Sat, May 2, 2015 at 2:06 PM, Peter Stirling <peter at pjstirling.plus.com>
wrote:

>  On 28/04/15 23:31, Reid Kleckner wrote:
>
>  On Wed, Apr 15, 2015 at 10:25 PM, Peter Stirling <
> peter at pjstirling.plus.com> wrote:
>>
>>  Visitor::RequestCompleteType() calls Sema::RequireCompleteType() (which
>> IMO has the wrong name, it returns false on what I would consider, from the
>> name, success).
>>
>
>  Much has been made about the sense of boolean return values in Clang. It
> isn't consistent or sane, but such is life. =/
>
>
>>  So, I don't construct the specializations for methods directly in my
>> code, I assume that some of the instantiation is performed by
>> RequireCompleteType(), but surely if I checked for SFINAE at that level
>> then I would lose EVERY methods for std::pair<int const, int const> and not
>> just the ones that involve mutation?
>>
>
>  I think RequireCompleteType won't instantiate all the member functions,
> like operator=, but you can look it up, and ask for an instantiation of it.
>
>
> Perhaps I misunderstand what you mean by 'instantiate' but this doesn't
> seem to be the case. When I walk the CXXRecordDecl for 'std::pair<int
> const, int const>' there ARE declarations for the methods that require
> mutation. My tool scans the AST for functions and methods and outputs a
> file containing functions that invoke the ones it finds, which is then
> compiled into a shared library, so what I want is protection against
> functions that can't be called.
>
> How do I go about asking for an instantiation of a method on its own?
>

Right, instantiating the class will create decls of all the member
functions, but the bodies will be empty because C++ essentially requires
that they be parsed lazily. I'd have to lookup the detailed mechanics, but
you should be able to look at the method decl, figure out that it needs
instantiation, instantiate it, and put the error trap around that.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150504/15d40b66/attachment.html>


More information about the cfe-dev mailing list