Skip to content

[Clang] Destructor definition is not compiled for local class in generic lambda initializing a variable template #132208

@MagentaTreehouse

Description

@MagentaTreehouse
template <class>
constexpr auto f{[] (auto) {
    struct OnScopeExit { ~OnScopeExit() {} }
    pending;
}};

int main() {
    f<int>(0);
}

See https://compiler-explorer.com/z/6vneqf93z.

Warning and linker error since Clang 15:

<source>:3:26: warning: inline function '(anonymous class)::operator()(int)::OnScopeExit::~OnScopeExit' is not defined [-Wundefined-inline]
    3 |     struct OnScopeExit { ~OnScopeExit() {} }
      |                          ^
<source>:4:5: note: used here
    4 |     pending;
      |     ^
1 warning generated.
ASM generation compiler returned: 0
<source>:3:26: warning: inline function '(anonymous class)::operator()(int)::OnScopeExit::~OnScopeExit' is not defined [-Wundefined-inline]
    3 |     struct OnScopeExit { ~OnScopeExit() {} }
      |                          ^
<source>:4:5: note: used here
    4 |     pending;
      |     ^
1 warning generated.
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eeceaa.o: in function `auto f<int>::{lambda(auto:1)#1}::operator()<int>(int) const':
<source>:5:(.text._ZNK1fIiEMUlT_E_clIiEEDaS1_[_ZNK1fIiEMUlT_E_clIiEEDaS1_]+0x14): undefined reference to `f<int>::{lambda(auto:1)#1}::operator()<int>(int) const::OnScopeExit::~OnScopeExit()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.constexprAnything related to constant evaluationlambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions