Skip to content

overeager dead code elimination of static assert of a template with static this #23239

Description

@crazymonkyyy
import std;
template typeinfoaa(alias F,S){
    S[TypeInfo] data;
    template has(T){
        static this(){
            data[typeid(T)]=F!T;
        }
        bool has()=> true; //look I just added it, therefore is has T :)
}}
template grabsizeof(T){
    enum grabsizeof=T.sizeof;
}
unittest{
    alias foo=typeinfoaa!(grabsizeof,typeof(int.sizeof));
    static assert(foo.has!int);
    static assert(foo.has!float);
    foo.data[typeid(int)].writeln;//crashes but I just asserted foo has an int :(
    foo.data[typeid(float)].writeln;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions