Skip to content

[clang] Valid constexpr noexcept expression with explicit lambda return type is rejected #157103

@TheAliceBaskerville

Description

@TheAliceBaskerville

Godbolt Demo

Clang version: 22.0.0git

Reproducer:

clang test.cpp

test.cpp:

template<typename>
constexpr void bar() noexcept([]<typename...>() -> bool { return true; }()) {}

int main() {
    bar<void>();
}

Clang output:

test.cpp:2:31: error: noexcept specifier argument is not a constant expression
    2 | constexpr void bar() noexcept([]<typename...>() -> bool { return true; }()) {}
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:2:16: note: in instantiation of exception specification for 'bar<void>' requested here
    2 | constexpr void bar() noexcept([]<typename...>() -> bool { return true; }()) {}
      |                ^
test.cpp:5:5: note: in instantiation of function template specialization 'bar<void>' requested here
    5 |     bar<void>();
      |     ^
test.cpp:2:31: note: undefined function 'operator()<>' cannot be used in a constant expression
    2 | constexpr void bar() noexcept([]<typename...>() -> bool { return true; }()) {}
      |                               ^
test.cpp:2:31: note: declared here

Expected behavior:

Successfully produces essentially empty executable.

Environment:

clang version 22.0.0git (https://github.com/llvm/llvm-project.git 779868de6975f6fd0ea17bb9a8e929037d3752d7)
Target: x86_64-w64-windows-gnu
Thread model: posix

Notes:

Removing -> bool results in successful compilation:

template<typename>
constexpr void bar() noexcept([]<typename...>() /*-> bool*/ { return true; }()) {}

int main() {
    bar<void>();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"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