[clang] [Clang][Sema] Revisit the fix for the lambda within a type alias template decl (PR #89934)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 25 22:14:24 PDT 2024


================
@@ -91,15 +91,60 @@ void bar() {
 
 namespace GH82104 {
 
-template <typename, typename...> int Zero = 0;
+template <typename, typename... D> int Value = sizeof...(D);
 
-template <typename T, typename...U>
-using T14 = decltype([]<int V = 0>() { return Zero<T, U...>; }());
+template <typename T, typename... U>
+using T14 = decltype([]<int V = 0>(auto Param) {
+  return Value<T, U...> + V + (int)sizeof(Param);
+}("hello"));
 
 template <typename T> using T15 = T14<T, T>;
 
 static_assert(__is_same(T15<char>, int));
 
+// FIXME: This still crashes because we can't extract template arguments T and U
+// outside of the instantiation context of T16.
+#if 0
+template <typename T, typename... U>
+using T16 = decltype([](auto Param) requires (sizeof(Param) != 1 && sizeof...(U) > 0) {
+  return Value<T, U...> + sizeof(Param);
+});
+static_assert(T16<int, char, float>()(42) == 2 + sizeof(42));
+#endif
----------------
zyn0217 wrote:

It turns out to be an evaluation context that eventually becomes the lambda context declaration.
Given that Matheus is going to refactor these codes shortly in the future, and we have not been correctly compiling this case for a long time (https://gcc.godbolt.org/z/sbYT1Pa91), I think I can delegate it to @mizvekov, and hopefully, he could fix the test here.

https://github.com/llvm/llvm-project/pull/89934


More information about the cfe-commits mailing list