Thread overview
[Issue 22334] TypeInfo is used in inexplicable places
Sep 24, 2021
Max Samukha
Sep 28, 2021
SHOO
Jun 04, 2022
Walter Bright
Dec 17, 2022
Iain Buclaw
Jan 03, 2023
Dennis
September 24, 2021
https://issues.dlang.org/show_bug.cgi?id=22334

Max Samukha <maxsamukha@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxsamukha@gmail.com

--- Comment #1 from Max Samukha <maxsamukha@gmail.com> ---
Assigning to an array's length may reallocate, and allocation still needs TypeInfo. You could try to get away with a lambda (not tested):

alias _ctfeAppend = (store, dat)
{
        alias T = typeof(dat);

        static if (is(T U: const(U)))
        {
            pragma(msg, U);
                U[] buf;
                buf.length = 1;
                buf[0] = dat;
                store = cast(T[])buf;
        }
};

However, the lambda hack is unusable for anything slightly less trivial (no overloading, if-constraints, variadic parameters, etc.)

--
September 28, 2021
https://issues.dlang.org/show_bug.cgi?id=22334

--- Comment #2 from SHOO <zan77137@nifty.com> ---
(In reply to Max Samukha from comment #1)
> Assigning to an array's length may reallocate, and allocation still needs TypeInfo. You could try to get away with a lambda (not tested):
> 
> alias _ctfeAppend = (store, dat)
> {
>     	alias T = typeof(dat);
> 
>         static if (is(T U: const(U)))
>         {
>             pragma(msg, U);
>                 U[] buf;
>                 buf.length = 1;
>                 buf[0] = dat;
>                 store = cast(T[])buf;
>         }
> };
> 
> However, the lambda hack is unusable for anything slightly less trivial (no overloading, if-constraints, variadic parameters, etc.)

Apparently, lambda does not solve the problem either...
And I doubt that reallocate is the cause, as the following code works:

-------------------------------------------
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;
        }
}
string[] getData()
{
        if (__ctfe)
        {
                string[] dat;
                dat._ctfeAppend("aaa");
                return dat;
        }
        return null;
}

extern(C) void main()
{
        static immutable dat = getData()[0];
        static assert(dat == "aaa");
}
-------------------------------------------

--
June 04, 2022
https://issues.dlang.org/show_bug.cgi?id=22334

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |betterC
                 CC|                            |bugzilla@digitalmars.com

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=22334

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
January 03, 2023
https://issues.dlang.org/show_bug.cgi?id=22334

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dkorpel@live.nl
         Resolution|---                         |DUPLICATE

--- Comment #3 from Dennis <dkorpel@live.nl> ---
The error now gives a location to the offending expression.
Allowing TypeInfo needing operations in CTFE only is covered by Issue 18472
like you mentioned.

*** This issue has been marked as a duplicate of issue 21477 ***

--