Skip to content

decltype in template lambdas crashes clang++ #57193

@OgnianM

Description

@OgnianM
#include <vector>
template<typename T>
decltype(T::z) doesnt_crash(T& v) {
    decltype(v.z) i = 0;

    i += v.z;
    return i;
}

int main() {
    struct test {
        int z;
    };


    auto crashes = []<typename T>(test& t) {
        decltype(t.z) v;
        return v;
    };

    auto also_crashes = []<typename T>(T& t) {
        std::vector<decltype(t.z)> v;
        return v;
    };

    auto no_crash = [](test& t) {
        std::vector<decltype(t.z)> v;
        return v;
    };

    test t{5};
    //also_crashes(t);
    doesnt_crash(t);
    no_crash(t);

    crashes.operator()<void>(t);
    also_crashes(t);
}

Only happens with C++11

$ clang++ --version 
clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicatelambdaC++11 lambda expressions

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions