August 05, 2022

On Friday, 5 August 2022 at 02:20:31 UTC, Steven Schveighoffer wrote:

>

On 8/4/22 9:51 PM, Paul Backus wrote:
Another option: use -vcg-ast, and have the compiler tell you what it's actually calling. It's not ignoring that line, it's just not doing what you think it's doing.

The output's not that useful...

import object;
struct S
{
	int n;
	void opOpAssign(string op)(S rhs) if (op == "/=")
	{
		n++;
	}
	void opOpAssign(string op)(S rhs) if (op == "/")
	{
	}
}
unittest
{
	S a = S(1);
	S b = S(2);
	a.opOpAssign(b);
	b.opOpAssign(a);
	assert(a.n == 2);
	assert(b.n == 3);
}
...

With this tiny example code it's clear by the end when there's only this one template instantiation:

opOpAssign!"/"
{
	pure nothrow @nogc @safe void opOpAssign(S rhs)
	{
	}

}
August 05, 2022

On 8/4/22 10:27 PM, jfondren wrote:

>

The output's not that useful...

import object;
struct S
{
     int n;
     void opOpAssign(string op)(S rhs) if (op == "/=")
     {
         n++;
     }
     void opOpAssign(string op)(S rhs) if (op == "/")
     {
     }
}
unittest
{
     S a = S(1);
     S b = S(2);
     a.opOpAssign(b);
     b.opOpAssign(a);

oof, I expected this to include the template parameters! I believe it normally does?

This is a bug that should be filed.

-Steve

August 05, 2022

On 8/5/22 11:24 AM, Steven Schveighoffer wrote:

>

On 8/4/22 10:27 PM, jfondren wrote:

>

     a.opOpAssign(b);
     b.opOpAssign(a);

oof, I expected this to include the template parameters! I believe it normally does?

It does not! I'm genuinely shocked.

void foo(string s, T)(T t) {}

void main()
{
   foo!"hi"(1);
}

outputs:

void foo(string s, T)(T t)
{
}
void main()
{
	foo(1);
	return 0;
}
>

This is a bug that should be filed.

Make that an enhancement request

-Steve

August 05, 2022

On Friday, 5 August 2022 at 15:24:16 UTC, Steven Schveighoffer wrote:

>

oof, I expected this to include the template parameters! I believe it normally does?
This is a bug that should be filed.

-Steve

Sorry, I don't get what you takling about?

The docs says:

The expression:
a op= b

is rewritten as:
a.opOpAssign!("op")(b)

There must no "=" to be applied.

The compiler creates this:

opOpAssign!"/"
{
	pure nothrow @nogc @safe void opOpAssign(S rhs)
	{
	}
}

as only valid call left. Fine for me since the other template is unused.

Same for your example:

foo!("hi", int)
{
	pure nothrow @nogc @safe void foo(int t)
	{
	}
}
August 05, 2022

On 8/5/22 3:53 PM, frame wrote:

>

On Friday, 5 August 2022 at 15:24:16 UTC, Steven Schveighoffer wrote:

>

oof, I expected this to include the template parameters! I believe it normally does?
This is a bug that should be filed.

-Steve

Sorry, I don't get what you takling about?

The docs says:

The expression:
a op= b

is rewritten as:
a.opOpAssign!("op")(b)

There must no "=" to be applied.

That's not what I was talking about here. I'm talking about -vcg-ast not telling you how it's calling the function.

>

The compiler creates this:

opOpAssign!"/"
{
     pure nothrow @nogc @safe void opOpAssign(S rhs)
     {
     }
}

as only valid call left. Fine for me since the other template is unused.

And what if the other template is used?

This is the AST from code that instantiates foo twice, and calls it 3 times. Tell me which calls are which?

import object;
void foo(string s, T)(T t)
{
}
void main()
{
	foo(1);
	foo(1);
	foo(1);
	return 0;
}
mixin _d_cmain!(); // omitted for brevity
foo!("hi", int)
{
	pure nothrow @nogc @safe void foo(int t)
	{
	}

}
foo!("bar", int)
{
	pure nothrow @nogc @safe void foo(int t)
	{
	}

}

-Steve

August 05, 2022

On Friday, 5 August 2022 at 21:24:13 UTC, Steven Schveighoffer wrote:

>

That's not what I was talking about here. I'm talking about -vcg-ast not telling you how it's calling the function.

Thanks for clarification.

I had that in mind but wasn't sure. I first thought it just get optimized away and in case of name/type collision would create another name for the function but after testing with static if it really shows that this assumption was wrong :D

1 2
Next ›   Last »