[all-commits] [llvm/llvm-project] 5e767b: Push immediate function context while transforming...

Daniel M. Katz via All-commits all-commits at lists.llvm.org
Thu Apr 25 00:41:47 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5e767bd7d16dcdfc1ad8b32ba399f969dd940f57
      https://github.com/llvm/llvm-project/commit/5e767bd7d16dcdfc1ad8b32ba399f969dd940f57
  Author: Daniel M. Katz <katzdm at gmail.com>
  Date:   2024-04-25 (Thu, 25 Apr 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/TreeTransform.h
    M clang/test/SemaCXX/cxx2a-consteval.cpp

  Log Message:
  -----------
  Push immediate function context while transforming lambdas in templates. (#89702)

The following program is [accepted](https://godbolt.org/z/oEc34Trh4) by
Clang, EDG, and MSVC, but rejected by Clang:
```cpp
#include <vector>

consteval auto fn() { return std::vector {1,2,3}; }

template <typename T = int>
void fn2() {
    (void)[]() consteval {
      for (auto e : fn()) {}
    };
}

void caller() {
    fn2();
}
```

The stated diagnostic is:
```cpp
<source>:8:21: error: call to consteval function 'fn' is not a constant expression
    8 |       for (auto e : fn()) {}
```

The body of the lambda should be evaluated as within an immediate
function context when the lambda is marked as `consteval`.

Co-authored-by: cor3ntin <corentinjabot at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list