[cfe-dev] class template methods
Peter Stirling
peter at pjstirling.plus.com
Wed Apr 15 22:25:21 PDT 2015
This does sound promising, but I'm not sure how to make use of it.
At the moment my walker (which is based on clang::ASTConsumer) has a
handler for class templates that looks like:
void Walker::TraverseClassTemplate(clang::ClassTemplateDecl const* d) {
TRACE(1, "walk template " + getDeclMetadataString(d));
bool was = inInstantiation;
inInstantiation = true;
for(auto decl : d->specializations()) {
visitor->RequestCompleteType(decl);
TraverseCXXRecord(decl);
}
inInstantiation = was;
}
Visitor::RequestCompleteType() calls Sema::RequireCompleteType() (which
IMO has the wrong name, it returns false on what I would consider, from
the name, success).
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?
On 14/04/15 18:26, Richard Smith wrote:
> On Tue, Apr 14, 2015 at 8:38 AM, Reid Kleckner <rnk at google.com
> <mailto:rnk at google.com>> wrote:
>
> Sounds a lot like a SFINAE test. Assuming you already have an AST
> with the class template instantiation, then you'd attempt to
> instantiate the assignment operator inside a SFINAETrap.
> Instantiation will either pass or fail and you'll get your answer,
> and you should be able to continue compilation or further queries
> normally.
>
>
> I think the above is about the best that you can do.
>
> One note: if an error occurs outside of the immediate context of the
> substitution, a SFINAETrap will not suppress it (which is actually a
> good thing in this case, because you cannot continue compilation
> normally after such an error -- any part of the AST that failed may be
> marked invalid, suppressing further errors in other contexts).
>
> On Mon, Apr 13, 2015 at 9:57 PM, Peter Stirling
> <peter at pjstirling.plus.com <mailto:peter at pjstirling.plus.com>> wrote:
>
> Hi,
>
> Is there a way to ask clang whether a method for an
> instantiation of a class template would be an error to call?
> (I only need yes/no)
>
> For example:
>
> std::pair has assignment operators defined, but for the
> instantiation std::pair<int const, int const> calling the
> assignment operators is an error, because you can't assign to
> int const.
>
> If clang can't tell me this, I'm looking at generating a
> translation unit with a call to the method, and then checking
> whether there was an error compiling it. Given that I will
> need to do this once per method, per instantiation, per
> template, (which looks to be in the thousands based on a test
> I just did) what is the best way to do this?
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu <mailto:cfe-dev at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu <mailto:cfe-dev at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150416/5bf30246/attachment.html>
More information about the cfe-dev
mailing list