Bug 17339 – ambiguous mangling with const alias argument
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-04-22T00:11:00Z
Last change time
2017-08-07T13:15:54Z
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2017-04-22T00:11:12Z
cat > bug.d << CODE
void bug(alias param)()
{
pragma(msg, __traits(identifier, param));
}
// works for enums
enum ENUM1 = 1;
enum ENUM2 = 1;
static assert(&bug!ENUM1 is &bug!ENUM2); // OK, same instances
static assert(bug!ENUM1.mangleof == bug!ENUM2.mangleof); // OK, same mangling
// works for values
auto VAL1 = 1;
auto VAL2 = 1;
static assert(&bug!VAL1 !is &bug!VAL2); // OK, different instances
static assert(bug!VAL1.mangleof != bug!VAL2.mangleof); // OK, different mangling
// fails for const values
const CONST1 = 1;
const CONST2 = 1;
static assert(&bug!CONST1 !is &bug!CONST2); // different instances
static assert(bug!CONST1.mangleof != bug!CONST2.mangleof); // but same mangling (like enum values)
CODE
dmd -c bug
----
ENUM1
VAL1
VAL2
CONST1
CONST2
bug.d(20): Error: static assert ("_D3bug13__T3bugVxii1Z3bugFNaNbNiNfZv" != "_D3bug13__T3bugVxii1Z3bugFNaNbNiNfZv") is false
----
Const module level template alias arguments are mangled as their constant value, just like enums, but the instances are not identical and are actually emitted multiple times.
0000000000000000 W pure nothrow @nogc @safe void bug.bug!(1).bug()
0000000000000008 W pure nothrow @nogc @safe void bug.bug!(1).bug()
Should be fixed one way or the other, either treating them like enums, or like non-const values.
Comment #1 by github-bugzilla — 2017-04-22T05:24:53Z
Commit pushed to master at https://github.com/dlang/dmdhttps://github.com/dlang/dmd/commit/b21f445de6e4e8aeb5447c09fde0e8fb179ce99c
workaround Issue 17339 - ambiguous mangling with const alias args
- with multiple definitions with identical mangling getsegment(".text", p)
returns the section from the previous instance and later the linker complains
about a group referencing an earlier section
- fixed by reusing the existing group section (while leaving the new one empty)
Comment #2 by uplink.coder — 2017-04-22T09:31:26Z
Instances should be merged!
Comment #3 by github-bugzilla — 2017-04-24T01:13:58Z