llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.47k stars 11.77k forks source link

Clang handles unqualified-ids incorrectly in lambda-expressions (P2036R3, P2579R0) #95664

Open ckwastra opened 4 months ago

ckwastra commented 4 months ago

Test code (Godbolt):

// -std=c++23
#include <cstdio>
template <class T> void print() { std::puts(__PRETTY_FUNCTION__); }
int main() {
  int x = 42;
  auto l0 = [=]() -> decltype((x)) { return (int &)x; };
  auto l1 = [=] /* () */ -> decltype((x)) { return x; };
  print<decltype(l0())>(); // Clang: int & (expected: const int &)
  print<decltype(l1())>(); // Clang: const int & (correct)
  [=] {
    [=](decltype((x)) y) {
      print<decltype(y)>(); // Clang: int & (expected: const int &)
    }((int &)x);
    print<decltype((x))>(); // Clang: const int & (correct)
  }();
}

The above code is derived from Example 1 in [expr.prim.id.unqual], which was introduced in P2036R3 and P2579R0.

llvmbot commented 4 months ago

@llvm/issue-subscribers-clang-frontend

Author: None (ckwastra)

Test code ([Godbolt](https://godbolt.org/z/M8jhEYo8s)): ```cpp // -std=c++23 #include <cstdio> template <class T> void print() { std::puts(__PRETTY_FUNCTION__); } int main() { int x = 42; auto l0 = [=]() -> decltype((x)) { return (int &)x; }; auto l1 = [=] /* () */ -> decltype((x)) { return x; }; print<decltype(l0())>(); // Clang: int & (expected: const int &) print<decltype(l1())>(); // Clang: const int & (correct) [=] { [=](decltype((x)) y) { print<decltype(y)>(); // Clang: int & (expected: const int &) }((int &)x); print<decltype((x))>(); // Clang: const int & (correct) }(); } ``` The above code is derived from [Example 1](https://timsong-cpp.github.io/cppwp/n4950/expr.prim.id.unqual#example-1) in [[expr.prim.id.unqual]](https://timsong-cpp.github.io/cppwp/n4950/expr.prim.id.unqual), which was introduced in [P2036R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2036r3.html) and [P2579R0](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2579r0.pdf).