[clang] [clang] Add diagnostic for friend declaration of closure type member (PR #191419)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 17 08:12:19 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}}
----------------
Endilll wrote:
Side note: this diagnostic is unfortunate in two ways:
- It should be issued for the source location of explicit instantiation, and "defined here" note should be issued for this location.
- It shouldn't say "explicitly specialized or instantiated", because we can determine which of them took place.
If you're looking for the next thing to work on, this sounds easy enough.
Please let me know if you're not interested, so that I can file an issue on our bug tracker instead.
https://github.com/llvm/llvm-project/pull/191419
More information about the cfe-commits
mailing list