[llvm-bugs] [Bug 48872] New: Rejects-valid for overloaded hidden non-template friend functions with mutually exclusive requires-clauses

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 25 04:39:41 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48872

            Bug ID: 48872
           Summary: Rejects-valid for overloaded hidden non-template
                    friend functions with mutually exclusive
                    requires-clauses
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: davveston at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210125/c39f7ea8/attachment.html>


More information about the llvm-bugs mailing list