Lambda capture of constexpr variables

In C++17, is a constexpr-declared variable is captured by copy in a lambda a core constant expression within the body of the lambda?

For example, GCC fails to compile the following example because it considers “i” not to be a constant expression within the body of the lambda, while Clang accepts it. Removing the capture of i reverses the behavior (Clang rejects it and GCC accepts it).


constexpr auto unwrap(std::integral_constant<int, I>) {
return I;

int main() {
constexpr auto i = std::integral_constant<int, 42>{};
constexpr auto l = i {
constexpr int x = unwrap(i);

GCC Wandbox link:
Clang Wandbox link:

On Stack Overflow, it was suggested that this is a bug in Clang and the closure type should not be a constant expression, but I wanted to get a second opinion from the Clang developers.

I’m invested in this question because I recently wrote a C++17 library that makes heavy use of Clang’s behavior in this case, but using this idiom makes it difficult to support GCC and Clang without a lot of ifdefs. So I’d like to confirm the correct interpretation of the standard before I decide on how to refactor my code.

Thanks for reading,