Skip to content

[clang] Linker regression with lambda NTTP containing consteval function call #169139

@k3DW

Description

@k3DW

This following code worked in Clang 20, but no longer works in Clang 21. It also works in MSVC and GCC. I'm wondering whether this is a regression. https://godbolt.org/z/aYTTorW3o

consteval int foo() {
    return 0;
}
template <auto fn>
void bar() {
    fn();
};
int main() {
    bar<[] { return foo(); }>();
}

The compile step succeeds, but the linking fails.

ASM generation compiler returned: 0
/opt/compiler-explorer/gcc-15.2.0/lib/gcc/x86_64-linux-gnu/15.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-a45c6a.o: in function `main::$_0::operator()() const':
<source>:9:(.text+0x3d): undefined reference to `foo()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Execution build compiler returned: 1
Build failed

Note that this code works fine when the lambda is not a temporary. https://godbolt.org/z/6xPPczena

// etc
int main() {
    constexpr auto x = [] { return foo(); };
    bar<x>();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions