From patchwork Thu Jul 15 16:37:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1505789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=wVURiTr9; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GQg6v0YnBz9sPf for ; Fri, 16 Jul 2021 02:38:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A9123989C0D for ; Thu, 15 Jul 2021 16:38:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A9123989C0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626367124; bh=QYyu/AZglTLY9SECI6OBZZRGI/t3+kKUDG/8zMC40Go=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wVURiTr9MpETmpzmwmJ5W3tHlqH4kKNQ98csBHmtFs/rAHiogfRIOrmWIXoS0UdbB a2UuD0I2AGlzVoSEWh4QOitE169988paaZVrsemggRMuoOQyyDIzUH1jduamUpG/qs N/CWHXNGTyN2dIBlj8KBu3dWI20wFj2H9AVOAzYM= 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 ESMTP id E43D03839405 for ; Thu, 15 Jul 2021 16:37:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E43D03839405 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-APYpwwflP4CE0SDigxkl8w-1; Thu, 15 Jul 2021 12:37:20 -0400 X-MC-Unique: APYpwwflP4CE0SDigxkl8w-1 Received: by mail-qt1-f200.google.com with SMTP id h17-20020ac858510000b0290251fc608f73so4470744qth.10 for ; Thu, 15 Jul 2021 09:37:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QYyu/AZglTLY9SECI6OBZZRGI/t3+kKUDG/8zMC40Go=; b=gUrIP+bho6V0iI6u7k7396nR9bmc4pgUSnDg3uwbxtWz9fdJR6BFH7RgUEE9H2Bs6T lW5Se8aWkD4RyFeY+Gk1uRQt23cvah5/7gjl2eUtzdpNEaOOJgo25ZjEgIAHY0R50Mgc mnFwnhT2Zcfe0098QIUKeZa8SwFJd+D5mPc5NNBJp1WFuyY/fhDd1uUZseSV/dRP6nRi EEZc7ABiuIpCa/u74AvAhPxjmlQkgciqUIyAOifrTi+j1FfYacuJI6K2isGirzGuPh/A 4VsjcWr2E32pLqJ8XmLKVvyPxXvhnUjg3noTXbtw0OF1QJmHyQIkHbbLhaCvc8CZwBMd Toig== X-Gm-Message-State: AOAM5316vVFFLGnbqm+NVdO+IsnIZH/zy/w1aZ0UGeAlTh/GSSp9yUbF wGs+nv8MNdPrsj4oOODdTOFPNQ0bqQVdu5N5ZCFUXfnKHdJzURk7/dB5YoHKHy+UDEF90wMTCtl oRTng2hs9p7FoZ3b9peCqMbtZqh52363LZ0wCr24DAoK0sfX6ZjYvsGmkeFOUy+MqNbE= X-Received: by 2002:a05:620a:e0d:: with SMTP id y13mr4962729qkm.14.1626367040092; Thu, 15 Jul 2021 09:37:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOAR5saNI1F+0yme3NGhIK061TRreaFLD0fKrd+KWoOYVWCueL0sICWRQm/kivT9Aqru65VA== X-Received: by 2002:a05:620a:e0d:: with SMTP id y13mr4962711qkm.14.1626367039859; Thu, 15 Jul 2021 09:37:19 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id f2sm2196902qte.67.2021.07.15.09.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 09:37:19 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: covariant reference return type [PR99664] Date: Thu, 15 Jul 2021 12:37:18 -0400 Message-Id: <20210715163718.1707452-1-ppalka@redhat.com> X-Mailer: git-send-email 2.32.0.264.g75ae10bc75 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.1 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This implements the wording changes of DR 960 which clarifies that two reference types are covariant only if they're both lvalue references or both rvalue references. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? DR 960 PR c++/99664 gcc/cp/ChangeLog: * search.c (check_final_overrider): Compare TYPE_REF_IS_RVALUE when the return types are references. gcc/testsuite/ChangeLog: * g++.dg/inherit/covariant23.C: New test. --- gcc/cp/search.c | 8 +++++++- gcc/testsuite/g++.dg/inherit/covariant23.C | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/inherit/covariant23.C diff --git a/gcc/cp/search.c b/gcc/cp/search.c index af41bfe5835..943671acff8 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -1948,7 +1948,13 @@ check_final_overrider (tree overrider, tree basefn) fail = !INDIRECT_TYPE_P (base_return); if (!fail) { - fail = cp_type_quals (base_return) != cp_type_quals (over_return); + if (cp_type_quals (base_return) != cp_type_quals (over_return)) + fail = 1; + + if (TYPE_REF_P (base_return) + && (TYPE_REF_IS_RVALUE (base_return) + != TYPE_REF_IS_RVALUE (over_return))) + fail = 1; base_return = TREE_TYPE (base_return); over_return = TREE_TYPE (over_return); diff --git a/gcc/testsuite/g++.dg/inherit/covariant23.C b/gcc/testsuite/g++.dg/inherit/covariant23.C new file mode 100644 index 00000000000..b27be15ef45 --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/covariant23.C @@ -0,0 +1,14 @@ +// PR c++/99664 +// { dg-do compile { target c++11 } } + +struct Res { }; + +struct A { + virtual Res &&f(); + virtual Res &g(); +}; + +struct B : A { + Res &f() override; // { dg-error "return type" } + Res &&g() override; // { dg-error "return type" } +};