From patchwork Wed Dec 6 02:21:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 174289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3862559vqy; Tue, 5 Dec 2023 19:41:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUa9G4YQGYQ6qyEwvUN6+Cci1qr20qLNYkfJQaIVr6lJDaWtdOgtj+n1bFV6YuLtvIQEz8 X-Received: by 2002:a05:620a:5624:b0:77e:fba3:4f0b with SMTP id vv4-20020a05620a562400b0077efba34f0bmr282761qkn.97.1701834091409; Tue, 05 Dec 2023 19:41:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701834091; cv=pass; d=google.com; s=arc-20160816; b=n9LNZltfLEjwg2SrSWP6s+9T07v0WyrYg2p4Wp/69zsvbX1MnA65HaGIzDh/xWsTcP DGEQryuqGHF5MnTbDPxC14iS1b5LpqSr5SB/yCyBBn6aGQkPWG3OAFNzK3HaGwE4GAKB uq9JH/lW8vvBHgROcKVncbjXyxjdLeoQGDd+4ODv1Vs5S6i8cWGEmW+cR+ql/9ohGDBp Tte4yI4qW0lwzTxwIJjaqu35TNKaQzmxJcZuYpN1/e+MiSiCjEiVjLaKJKIxDhkyJqLo Qya7sQaqE3eQ38weYJ02l11Nc0JBI3ZxQIyr6kPN2Cfp000gviStAaMl5cA2JjJHEHUU Z+Mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=ExWilUsfx9bU3dH3r4omcq4zw839ACnsstz6QmdMqgM=; fh=A8QyYu5CSPUbDE08bDTmwelqRkZohphqj3UolZCnkmo=; b=FWKSaH+2vkNjIARncXuaxf0Q2qw1LLYelh9pQDUVetYDDQc23kxPwL1YYG2moIvuFO Lwqu0CiyCzGzBzyvQ7QHryh0LU+FFPK45KMSQ6ztezUtAR4N7kixy2x52njURQOOVYUQ 6SefkRNaZR+ItTSGnn3nzfWtN/F5artNofT74zwozd6EIFb9FHlNsQN6hwJdLHq8apQv JYrGeqySiaQ4euiVfxOFndosFLehWYQJtAVB0eiprnADlhqvHWXFApfHS8Ex//crcs3w ryEXA0UbnvMKv/pwEWvjZNmD5VKTsVo/ldu40kBJwKZg073AUDPgsMjQzErycwZ1979E tROg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="PMUN/owr"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c21-20020a37e115000000b0077f2b1e697bsi525263qkm.747.2023.12.05.19.41.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 19:41:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="PMUN/owr"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E02C384F485 for ; Wed, 6 Dec 2023 02:21:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C8A96385840C for ; Wed, 6 Dec 2023 02:21:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8A96385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C8A96385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701829270; cv=none; b=g1QIqr+3zm1fB1Cem8ortS+dr9le4yMKqDaShqV1MwTI5hWA/hxNtNXLcmXeLSSlAturqssoQvIhbhFFPYHBQvN4nfNrbu+Mes8cpgDdeo7CP5eEO0x7TE0J+WV7rvjcUJoESaeViKBJ9Sygs2GPDngdklTWz99jyr5yYEgYTyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701829270; c=relaxed/simple; bh=cxkVLLiQWnglws/Z94ynPAk0pE3uduCTDVKftIE7ET4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=M32rHrWn9XR8jm1qnKe3PpYMY91UaPPJbt/8VYnclIHjFbYSAp2awkTWbHwF/l/k5A81aBa2Pm3EAzk51N1P0+6n1iiwi7WUW0p6xuLT9CebnBJA4UI0fmaYUlv1WuGr/bYyCOHF8VLwol6GkemhNnUB6eSs+CdUlQybt+7360c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701829268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ExWilUsfx9bU3dH3r4omcq4zw839ACnsstz6QmdMqgM=; b=PMUN/owrbUkH7VyvLGqn8/Om5PFt/gk2oU9olaTXa/P2UGfyW1JmQ3C9DI/gD1JM3CHoJS +4AvccsTQ8U+2wTzZeEIAf1b6QDNGxG85LMnqRUHCvEyW56j4MsE7pJxVex9+Eg3Hpb6TY d3qqMlWMJ6QR1YatfEmzigTT5LfuT6o= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-344-0hTcDVu8O7mk19y9Iu5IxA-1; Tue, 05 Dec 2023 21:21:06 -0500 X-MC-Unique: 0hTcDVu8O7mk19y9Iu5IxA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-423e684dc6eso3901951cf.1 for ; Tue, 05 Dec 2023 18:21:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701829265; x=1702434065; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ExWilUsfx9bU3dH3r4omcq4zw839ACnsstz6QmdMqgM=; b=vjeHl83VQd2WxTHbqiA4xobLUW9yb97v6+Fdk9PJaFHlXN6wCqg1Z+n0yKJCgvzFr+ huTRkKgNbKojuOnILh06JkC9xxFLymGYdv1flpu4LL5jcS/Ir6iQCaN43EdYeSn5NHfN PLVRI2fEco8HGzK+egwH4ec1S5wUAXHS5fuGRT7A36tSmbYMEsHN1ejv3xqn4/xgZwhR eawUxBPNiXSJA5ssRlOzYDfJgpRRM4U/Ck/eNi1v9xnS/3BWfZAdvEQSmYSbq06OUDG2 zXD7TEkHPD/blUm9FwP+TOy2cMHjQ56RMcz+mmW547mGcN2V46FDe9LeEQe5fMZDkMcH 0i6g== X-Gm-Message-State: AOJu0Yx1F4427Y1ztoKDdKhnKkS3g0olVyQTBmMDHir0qaPk2L78q0m+ 2uE/Lfb74xkPXifLy/Y0RYtPnCU0znXLlT+Vyp8IF0vcLyRZV1NDbZaUWBFddHFRJC7vmpJDrlu Ed/Owr1swTAvGYfwGyxW3eLoPJCelH3JCuyRhhVrMSBGHyCoAWoWNjQC8Hhlm6r1zveqRN4OvRA == X-Received: by 2002:a05:622a:1883:b0:423:6e9c:2de9 with SMTP id v3-20020a05622a188300b004236e9c2de9mr244277qtc.17.1701829265066; Tue, 05 Dec 2023 18:21:05 -0800 (PST) X-Received: by 2002:a05:622a:1883:b0:423:6e9c:2de9 with SMTP id v3-20020a05622a188300b004236e9c2de9mr244263qtc.17.1701829264619; Tue, 05 Dec 2023 18:21:04 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id f5-20020ac84985000000b0041eb13a8195sm5570445qtq.61.2023.12.05.18.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 18:21:03 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, waffl3x@protonmail.com Subject: [PATCH RFA (libstdc++)] c++: partial ordering of object parameter [PR53499] Date: Tue, 5 Dec 2023 21:21:01 -0500 Message-Id: <20231206022101.1695009-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784502384344798765 X-GMAIL-MSGID: 1784502384344798765 Tested x86_64-pc-linux-gnu. Are the library test changes OK? A reduced example of the issue is at https://godbolt.org/z/cPxrcnKjG -- 8< -- Looks like we implemented option 1 (skip the object parameter) for CWG532 before the issue was resolved, and never updated to the final resolution of option 2 (model it as a reference). More recently CWG2445 extended this handling to static member functions; I think that's wrong, and have opened CWG2834 to address that and how explicit object member functions interact with it. The FIXME comments are to guide how the explicit object member function support should change the uses of DECL_NONSTATIC_MEMBER_FUNCTION_P. The library testsuite changes are to make partial ordering work again between the generic operator- in the testcase and _Pointer_adapter::operator-. DR 532 PR c++/53499 gcc/cp/ChangeLog: * pt.cc (more_specialized_fn): Fix object parameter handling. gcc/testsuite/ChangeLog: * g++.dg/template/partial-order4.C: New test. * g++.dg/template/spec26.C: Adjust for CWG532. libstdc++-v3/ChangeLog: * testsuite/23_containers/vector/ext_pointer/types/1.cc * testsuite/23_containers/vector/ext_pointer/types/2.cc (N::operator-): Make less specialized. --- gcc/cp/pt.cc | 68 ++++++++++++++----- .../g++.dg/template/partial-order4.C | 17 +++++ gcc/testsuite/g++.dg/template/spec26.C | 10 +-- .../vector/ext_pointer/types/1.cc | 4 +- .../vector/ext_pointer/types/2.cc | 4 +- 5 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/partial-order4.C base-commit: 0e7fee57c00ae17611651e0b057dc03b6e276b82 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 924a20973b4..4b2af4f7aca 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -25218,27 +25218,61 @@ more_specialized_fn (tree pat1, tree pat2, int len) bool lose1 = false; bool lose2 = false; - /* Remove the this parameter from non-static member functions. If - one is a non-static member function and the other is not a static - member function, remove the first parameter from that function - also. This situation occurs for operator functions where we - locate both a member function (with this pointer) and non-member - operator (with explicit first operand). */ - if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl1)) + /* C++17 [temp.func.order]/3 (CWG532) + + If only one of the function templates M is a non-static member of some + class A, M is considered to have a new first parameter inserted in its + function parameter list. Given cv as the cv-qualifiers of M (if any), the + new parameter is of type "rvalue reference to cv A" if the optional + ref-qualifier of M is && or if M has no ref-qualifier and the first + parameter of the other template has rvalue reference type. Otherwise, the + new parameter is of type "lvalue reference to cv A". */ + + if (DECL_STATIC_FUNCTION_P (decl1) || DECL_STATIC_FUNCTION_P (decl2)) { - len--; /* LEN is the number of significant arguments for DECL1 */ - args1 = TREE_CHAIN (args1); - if (!DECL_STATIC_FUNCTION_P (decl2)) - args2 = TREE_CHAIN (args2); - } - else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl2)) - { - args2 = TREE_CHAIN (args2); - if (!DECL_STATIC_FUNCTION_P (decl1)) + /* Note C++20 DR2445 extended the above to static member functions, but + I think think the old G++ behavior of just skipping the object + parameter when comparing to a static member function was better, so + let's stick with that for now. This is CWG2834. --jason 2023-12 */ + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl1)) /* FIXME or explicit */ { - len--; + len--; /* LEN is the number of significant arguments for DECL1 */ args1 = TREE_CHAIN (args1); } + else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl2)) /* FIXME or explicit */ + args2 = TREE_CHAIN (args2); + } + else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl1) /* FIXME implicit only */ + && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl2)) + { + /* Note DR2445 also (IMO wrongly) removed the "only one" above, which + would break e.g. cpp1y/lambda-generic-variadic5.C. */ + len--; + args1 = TREE_CHAIN (args1); + args2 = TREE_CHAIN (args2); + } + else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl1) /* FIXME implicit only */ + || DECL_NONSTATIC_MEMBER_FUNCTION_P (decl2)) + { + /* The other is a non-member or explicit object member function; + rewrite the implicit object parameter to a reference. */ + tree ns = DECL_NONSTATIC_MEMBER_FUNCTION_P (decl2) ? decl2 : decl1; + tree &nsargs = ns == decl2 ? args2 : args1; + tree obtype = TREE_TYPE (TREE_VALUE (nsargs)); + + nsargs = TREE_CHAIN (nsargs); + + cp_ref_qualifier rqual = type_memfn_rqual (TREE_TYPE (ns)); + if (rqual == REF_QUAL_NONE) + { + tree otherfirst = ns == decl1 ? args2 : args1; + otherfirst = TREE_VALUE (otherfirst); + if (TREE_CODE (otherfirst) == REFERENCE_TYPE + && TYPE_REF_IS_RVALUE (otherfirst)) + rqual = REF_QUAL_RVALUE; + } + obtype = cp_build_reference_type (obtype, rqual == REF_QUAL_RVALUE); + nsargs = tree_cons (NULL_TREE, obtype, nsargs); } /* If only one is a conversion operator, they are unordered. */ diff --git a/gcc/testsuite/g++.dg/template/partial-order4.C b/gcc/testsuite/g++.dg/template/partial-order4.C new file mode 100644 index 00000000000..89555ab7060 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/partial-order4.C @@ -0,0 +1,17 @@ +// DR 532 +// PR c++/53499 +// [temp.func.order] says that we do ordering on the first parameter. + +struct A +{ + template + bool operator==(T); +}; + +template +bool operator==(T, U); + +int main() +{ + A() == A(); +} diff --git a/gcc/testsuite/g++.dg/template/spec26.C b/gcc/testsuite/g++.dg/template/spec26.C index fad8e3e1519..253d4211153 100644 --- a/gcc/testsuite/g++.dg/template/spec26.C +++ b/gcc/testsuite/g++.dg/template/spec26.C @@ -1,13 +1,15 @@ -// { dg-do run } +// { dg-do compile { target c++11 } } // Copyright (C) 2005 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 16 Sep 2005 // PR 23519 template specialization ordering (DR214) // Origin: Maxim Yegorushkin +// DR532 clarified that the * expression is ambiguous. + struct A { - template int operator+(T&) { return 1;} + template int operator+(T&) = delete; }; template struct B @@ -16,7 +18,7 @@ template struct B template int operator*(R&) {return 3;} }; -template int operator-(B, R&) {return 4;} +template int operator-(B, R&) = delete; template int operator+(A&, B&) { return 5;} template int operator*(T &, A&){return 6;} @@ -30,6 +32,6 @@ int main() if ((b - a) != 2) return 2; - if ((b * a) != 6) + if ((b * a) != 6) // { dg-error "ambiguous" } return 3; } diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc index 5b3c673898e..2819851076c 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc @@ -36,8 +36,8 @@ namespace N X operator+(T, std::size_t) { return X(); } - template - X operator-(T, T) + template + X operator-(T, U) { return X(); } } diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc index cc9519ee618..6c00d1568ae 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc @@ -38,8 +38,8 @@ namespace N X operator+(T, std::size_t) { return X(); } - template - X operator-(T, T) + template + X operator-(T, U) { return X(); } }