[Issue 17339] New: ambiguous mangling with module level const values as alias template argument

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Apr 21 17:11:12 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17339

          Issue ID: 17339
           Summary: ambiguous mangling with module level const values as
                    alias template argument
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: code at dawg.eu

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.

--


More information about the Digitalmars-d-bugs mailing list