[clang] [Clang] diagnose deleted/default redeclaration of defined friend functions (PR #136717)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 22 10:29:33 PDT 2025


================
@@ -274,26 +274,22 @@ void operators() {
 
 namespace gh135506 {
 struct a {
-  // FIXME: We currently don't diagnose these invalid redeclarations if the
-  // second declaration is defaulted or deleted. This probably needs to be
-  // handled in ParseCXXInlineMethodDef() after parsing the defaulted/deleted
-  // body.
-  friend consteval int f() { return 3; }
-  friend consteval int f() = delete("foo");
+  friend consteval int f() { return 3; }    // expected-note {{previous definition is here}}
+  friend consteval int f() = delete("foo"); // expected-error {{redefinition of 'f'}}
 
-  friend consteval int g() { return 3; }
-  friend consteval int g() = delete;
+  friend consteval int g() { return 3; } // expected-note {{previous definition is here}}
+  friend consteval int g() = delete;     // expected-error {{redefinition of 'g'}}
 
-  friend int h() { return 3; }
-  friend int h() = delete;
+  friend int h() { return 3; } // expected-note {{previous definition is here}}
+  friend int h() = delete;     // expected-error {{redefinition of 'h'}}
 
-  friend consteval int i() = delete; // expected-note {{previous definition is here}}
+  friend consteval int i() = delete;     // expected-note {{previous definition is here}}
   friend consteval int i() { return 3; } // expected-error {{redefinition of 'i'}}
----------------
shafik wrote:

It feels like this should be a separate diagnostic, attempting to define a deleted function but this looks like an existing limitation and probably not to be fixed here.

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


More information about the cfe-commits mailing list