Uninstantiated default argument handling issue

Richard Smith richard at metafoo.co.uk
Thu Nov 13 17:57:23 PST 2014


On Sat, Nov 8, 2014 at 1:21 AM, Abramo Bagnara <abramo.bagnara at bugseng.com>
wrote:

>
> template<typename T> void f2(T a, T b = T()) { }
>
> void m() {
>   f2(10);
>   f2(10);
>   f2(10);
>   f2(10);
> }
>
> Checking the AST generated for the source above I've seen that the
> default argument expression is not instantiated in specialization of
> function f2, but instead such transformation is done (and redone) in the
> calls to f2.
>
> In this way:
>
> - we have dependent expr in the declaration of fully instantiated
> functions (that is unexpected, at least for me)
>
> - we have multiple copies of the same expression (one for each call)
>
> Is this deliberate?


It's deliberate that we delay instantiating the exception specification
until it's used; that's what the C++ standard says should happen. As far as
I know, it's not deliberate that we instantiate the default argument each
time it's used; that seems like a bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141113/2b6833dc/attachment.html>


More information about the cfe-commits mailing list