[clang] [Clang] Ensure default arguments in friend declarations are only allowed in defining declarations to prevent multiple reachable declarations (PR #113777)

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 7 01:23:01 PST 2024


================
@@ -185,3 +185,21 @@ template<typename T> struct S {
   friend void X::f(T::type);
 };
 }
+
+namespace GH113324 {
+template <typename = int> struct ct {
+  friend void f1(ct, int = 0);               // expected-error {{friend declaration specifying a default argument must be a definition}}
+  friend void f2(ct a, ct = decltype(a){ }); // expected-error {{friend declaration specifying a default argument must be a definition}}
+};
+
+template<class T> using alias = int;
+template<typename T> struct C {
+  friend void f3(C, int a = alias<T&>(1)); // expected-error {{friend declaration specifying a default argument must be a definition}}
----------------
a-tarasyuk wrote:

@mizvekov Could you let me know if you meant these [changes](https://github.com/llvm/llvm-project/pull/113777/files#diff-b0cb098ce09d66d899c8c9743edb974ce84976dfda43dbe21ee1e1a2d4b2855cR197-R198?)?

@zyn0217 could you please review this PR when you have a moment?



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


More information about the cfe-commits mailing list