[clang] [clang] Add diagnostic for friend declaration of closure type member (PR #191419)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 08:47:49 PDT 2026


================
@@ -222,3 +222,33 @@ template <template <typename> class Template, typename Argument>
 using Bind = Instantiate<Internal<Template>::template Bind, Argument>;
 #endif
 } // namespace cwg1794
+
+namespace cwg1780 { // cwg1780: 23
+#if __cplusplus >= 201103L
+
+auto l = []() -> int { return 5; };
+using L = decltype(l);
+class A {
+#if __cplusplus >= 201703L
+    friend constexpr auto L::operator()() const -> int; // expected-error{{a member of a lambda should not be the target of a friend declaration}}
+#else
+    friend auto L::operator()() const -> int; // expected-error{{a member of a lambda should not be the target of a friend declaration}}
+#endif
+};
+
+#if __cplusplus >= 201402L
+auto gl = [](auto a) { return 5; };
+using GL = decltype(gl);
+
+template <>
+auto GL::operator()(int a) const { // expected-error{{lambda call operator should not be explicitly specialized or instantiated}}
+    return 6;
+}
+
+auto gll = [](auto a) { return 5; }; // expected-error{{lambda call operator should not be explicitly specialized or instantiated}}
----------------
StefanPaulet wrote:

Yes, I will start working on this. Thanks for the suggestion!
Since the PR was merged, how should I go about the changes that you requested? Can I include them in my follow-up PR about the instantiation/specialization diagnostics?

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


More information about the cfe-commits mailing list