[Issue 19674] multiple local template function with same name don't work
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 21 10:52:01 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19674
RazvanN <razvan.nitu1305 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |razvan.nitu1305 at gmail.com
--- Comment #4 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Iain Buclaw from comment #3)
> Or, granted that this is an error.
>
> void main()
> {
> import core.stdc.stdio;
> {
> static int[] a;
> a ~= 3;
> if (a.length)
> printf("[%d]\n",a[0]);
> else
> printf("[]\n");
> }
> {
> static int[] a;
> a ~= 3;
> if (a.length)
> printf("[%d]\n",a[0]);
> else
> printf("[]\n");
> }
> }
>
> Reject the given example for functions as well.
(In reply to Iain Buclaw from comment #2)
> A frame gets created in main() with both 'a' vars as fields.
>
> (gdb) pt this
> type = struct FRAME.D main {
> int [] a;
> int [] a;
> } * const
>
> (gdb) p *this
> $1 = {a = {3, 3}, a = 0x0}
>
>
> However, looks like only one add() is sent to the code generation phase to
> be emitted.
>
> In this case, the first add(), which only appends to the first field in the
> frame.
>
> Two functions should be generated, though need to avoid the pitfall of
> conflicting symbols.
I think that the guideline should be what happens when the functions are not
templated:
void main()
{
import std.stdio;
{
auto a = new int[0];
void add(int x)
{
a ~= x;
}
add(3);
writefln("%s",a); //should be [3] and is
}
{
auto a = new int[0];
void add(int x)
{
a ~= x;
}
add(3);
writefln("%s",a); //should be [3] but isn't
}
}
This yields:
Error: declaration onlineapp.main.add is already defined in another scope in
main at line 6
This should be the result for templated functions also.
--
More information about the Digitalmars-d-bugs
mailing list