[cfe-dev] class template methods

Richard Smith richard at metafoo.co.uk
Tue Apr 14 10:26:08 PDT 2015


On Tue, Apr 14, 2015 at 8:38 AM, Reid Kleckner <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>
> 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
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>
>
> _______________________________________________
> cfe-dev mailing list
> 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/20150414/b85eacce/attachment.html>


More information about the cfe-dev mailing list