Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dfrib mannequin opened this issue Jan 25, 2021 · 5 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts

Comments

@dfrib
Copy link
Mannequin

dfrib mannequin commented Jan 25, 2021

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)

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@royjacobson royjacobson added the concepts C++20 concepts label Oct 6, 2022
@usx95 usx95 moved this to Triage Group 3 in C++ 20 in Clang Oct 30, 2022
@zygoloid
Copy link
Collaborator

I believe the current thinking on a mangling rule here is described in this comment: itanium-cxx-abi/cxx-abi#24 (comment)

@erichkeane
Copy link
Collaborator

I did a bit of work for that Itanium ABI issue at one point (though my patch desperately needs a rebase, since most of it is invalid now that we do the pre-calculation of constrained-friends), but it was held up on @rjmccall wanting Itanium to accept that comment first.

@erichkeane
Copy link
Collaborator

Commit I was working on: https://reviews.llvm.org/D126818

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Nov 2, 2022
@llvmbot
Copy link
Member

llvmbot commented Nov 2, 2022

@llvm/issue-subscribers-clang-frontend

@erichkeane
Copy link
Collaborator

Just did some additional work on the patch, so it should be ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts
Projects
Status: Done
Development

No branches or pull requests

5 participants