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

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 14:37:52 PST 2024


================
@@ -6018,6 +6018,13 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl,
     } else {
       assert(Param && "can't use default arguments without a known callee");
 
+      // C++ [dcl.fct.default]p4
+      //   If a friend declaration D specifies a default argument expression,
+      //   that declaration shall be a definition.
----------------
mizvekov wrote:

```suggestion
      // FIXME: We don't track member specialization info for non-defining friend declarations,
      // so we will not be able to later find the function pattern.
      // As a workaround, don't instantiate the default argument in this case.
      // This is correct per wording and only an error recovery issue, as per [dcl.fct.default]p4,
      // "if a friend declaration D specifies a default argument expression,
      // that declaration shall be a definition."
```
As the way it was stated before, the comment gave the impression that it was implementing that wording. But that is done elsewhere. Here we are just using the wording to justify a workaround.


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


More information about the cfe-commits mailing list