Skip to content

Rejects-valid for overloaded hidden non-template friend functions with mutually exclusive requires-clauses #48216

@dfrib

Description

@dfrib
mannequin
Bugzilla Link 48872
Version trunk
OS Linux
CC @zygoloid

Extended Description

As per [defns.signature.friend] in N4861, the signature of a non-template friend function includes a trailing requires-clause, if it is present. Moreover, [over.dcl]/1 states that two function declarations declare different functions if they have different trailing requires-clauses.

The following example fails to compile for Clang (-std=c++2b, 12.0.0 trunk):

 #include <iostream>

 template<int N>
 struct S {
     friend void foo(int) requires (N == 1) { std::cout << "1\n"; }
     friend void foo(int) requires (N == 2) { std::cout << "2\n"; }
     operator int() const { return 0; }
 };

 int main() {
     foo(S<1>{}); // 1
     foo(S<2>{});
       // error: definition with same mangled 
       //        name '...' as another definition
 }

which is arguably incorrect, as the two, separate (by separate requires-clauses) friend declarations (that are also definitions) should not generate the same mangled name.


(Constrained hidden non-template friends was added as per NS US115 of P2103R0; http://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p2103r0.html)

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 concepts

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions