Evaluating __FILE__ and __LINE__ of caller?

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Mar 2 18:19:46 PST 2012


On 3/3/12, Adam D. Ruppe <destructionator at gmail.com> wrote:
> Since some time last year, it works on all functions, just
> use regular default parameters:

Right, but what about template bloat? DMD doesn't seem to merge these
templates. It can try to inline them, but it's very easy to break the
inliner. E.g.:

int myFunc(string file = __FILE__, int line = __LINE__)(int x)
{
    if (x == 1)
        return x;
    // missing else breaks inliner: Issue 7625
    return x + 1;
}

void main(string[] arg)
{
    if (arg.length)
    {
        x = myFunc(1);
    }
    else
    {
        x = myFunc(2);
    }
}

$ dmd -map -release -O -inline test.d
test.map:
 0002:00000054
_D4test34__T6myFuncVAyaa6_746573742e64Vi11Z6myFuncFiZi 00402054
 0002:00000058
_D4test34__T6myFuncVAyaa6_746573742e64Vi15Z6myFuncFiZi 00402058


More information about the Digitalmars-d-learn mailing list