www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22334] New: TypeInfo is used in inexplicable places

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

          Issue ID: 22334
           Summary: TypeInfo is used in inexplicable places
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: zan77137 nifty.com

This code doesn't work with `-betterC`:
-------------------------------------------
void _ctfeAppend(T)(ref T[] store, T dat)
{
        static if (is(T U: const(U)))
        {
                U[] buf;
                buf.length = 1;
                buf[0] = dat;
                store = cast(T[])buf;
        }
}

void put(R, E)(R, E){}

struct Data{ string text;}

Data[] getData(string str)
{
        if (__ctfe)
        {
                Data[] ret;
                Data tmp;
                tmp.text._ctfeAppend(str[0]);
                ret._ctfeAppend(tmp);
                return ret;
        }
        return null;
}

void foo(Data dat, DstRange)(DstRange dst)
{
        put(dst, dat);
}

extern(C) void main()
{
        static immutable dat = getData("a")[0];
        char[] buf;
        foo!dat(buf);
}
-------------------------------------------

Even though the above code does not use TypeInfo at first glance, the compiler
says "Error: `TypeInfo` cannot be used with -betterC".

By the way, in CTFE, there should be no restriction on using TypeInfo, even if
it is betterC.
The issue related to the relaxation of the CTFE+BetterC restrictions relates to
the following:
https://issues.dlang.org/show_bug.cgi?id=18472

--
Sep 24