www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17339] New: ambiguous mangling with module level const values


          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 puremagic.com
          Reporter: code 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
// 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)

dmd -c bug
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.

Apr 21 2017