[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
Wed Apr 24 19:50:16 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:

I have to admit we still have lots of edge cases that our current approach (i.e. by extracting template arguments from the type alias instantiation context) doesn't cover. However, I think we can still land this patch (because it addresses the regressions and covers a number of cases) and probably come up with another solution later.

Perhaps, I *think* one promising approach is to change the `TypeAliasTemplateDecl` to a kind of `DeclContext` and thereby we can invent something e.g. `TypeAliasTemplateSpecializationDecl` so that they can be handled like what we do for member function templates.

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


More information about the cfe-commits mailing list