From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 532073857350 for ; Tue, 16 May 2023 19:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 532073857350 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684265731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=64i142T7MDARqyesDzlVpPeTJsioqGA9yQDObdoQN0Q=; b=g+t99weKCWIVC1FJUIsP2jreqmtZEhDjex9oNf1muuXI54vo15FedRfj0oNr2j01qHX5yL rM1od/QNyN0OFi/AzBusfi25DPeGohd9VKKO1PWV7aIKCP1uZd4CGszetKQYPjxN8d8Tnu K9/QIYiKvTX76suwU94WwHtsC8clRxc= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-2Q6Pi0jbNUyo5o9Ryb0Wnw-1; Tue, 16 May 2023 15:35:29 -0400 X-MC-Unique: 2Q6Pi0jbNUyo5o9Ryb0Wnw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7578369dff3so508768485a.0 for ; Tue, 16 May 2023 12:35:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684265729; x=1686857729; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=64i142T7MDARqyesDzlVpPeTJsioqGA9yQDObdoQN0Q=; b=i9T27n7i6NU1i8asSysaJSIyz5rij58PorubZTXY1G4/O9UxVh29nt2lq5tLwlqrl2 tkMMF4+zsEDCGh0XyW1W7xUnTNUwkMOTP6+Vl1IZFNh08LLTIAXekDAyJx6s/3T1UTHz WFsHrzLf5sFhQQoeFsUGXwVSih3+Nz8gVrWLEenf9mrL2FC+azf6TwES1XWS4x+m0zlk RadLW9N4z7uE5niZKHnunti5e8PG3CEiPQibpKYwCQhDp14fcnmXqfBR2GM7zjJkzJSB +8GnM2Cke8k8OtItV3BPkU2BTXNLgiwsWXxS4DBXUeyUBGgB06iyn+yQDj/CPuSu3XoA Z7CA== X-Gm-Message-State: AC+VfDyULBoZ3l8ClEvQiJGP+m2+6JQamojwVBHg/RBLjNyb++I7ReNK 6NpZsJeYUgchY5xYboJW7J3s70BNh/0LP0fxAlpRGmGYQcCoK1J/vPvLu3SJaPnSsu1jBp3cyvl qCFT0DRK6VuMDyoNP6g== X-Received: by 2002:a05:622a:c9:b0:3f3:87d8:c6f4 with SMTP id p9-20020a05622a00c900b003f387d8c6f4mr54811772qtw.7.1684265729255; Tue, 16 May 2023 12:35:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50iO38nVpJ9N0Zd/FV+zOk2BpOwRtx1A/6Z47ZZmUkiZPNLEOmn1romj77aCcxkht6uNhing== X-Received: by 2002:a05:622a:c9:b0:3f3:87d8:c6f4 with SMTP id p9-20020a05622a00c900b003f387d8c6f4mr54811746qtw.7.1684265728952; Tue, 16 May 2023 12:35:28 -0700 (PDT) Received: from [192.168.1.108] (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 oo23-20020a05620a531700b00758fef02a08sm99735qkn.6.2023.05.16.12.35.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 12:35:28 -0700 (PDT) Message-ID: <90b17685-94ff-8dbb-6fa2-25177225a94c@redhat.com> Date: Tue, 16 May 2023 15:35:26 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] c++: -Wdangling-reference not suppressed in template [PR109774] To: Marek Polacek , GCC Patches References: <20230516191354.155428-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20230516191354.155428-1-polacek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TRACKER_ID,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 List-Id: On 5/16/23 15:13, Marek Polacek wrote: > In check_return_expr, we suppress the -Wdangling-reference warning when > we're sure it would be a false positive. It wasn't working in a > template, though, because the suppress_warning call was never reached. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk and 13.2? OK. > PR c++/109774 > > gcc/cp/ChangeLog: > > * typeck.cc (check_return_expr): In a template, return only after > suppressing -Wdangling-reference. > > gcc/testsuite/ChangeLog: > > * g++.dg/warn/Wdangling-reference13.C: New test. > --- > gcc/cp/typeck.cc | 6 ++--- > .../g++.dg/warn/Wdangling-reference13.C | 23 +++++++++++++++++++ > 2 files changed, 26 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/warn/Wdangling-reference13.C > > diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc > index 53ac925a092..c225c4e2423 100644 > --- a/gcc/cp/typeck.cc > +++ b/gcc/cp/typeck.cc > @@ -11236,9 +11236,6 @@ check_return_expr (tree retval, bool *no_warning) > build_zero_cst (TREE_TYPE (retval))); > } > > - if (processing_template_decl) > - return saved_retval; > - > /* A naive attempt to reduce the number of -Wdangling-reference false > positives: if we know that this function can return a variable with > static storage duration rather than one of its parameters, suppress > @@ -11250,6 +11247,9 @@ check_return_expr (tree retval, bool *no_warning) > && TREE_STATIC (bare_retval)) > suppress_warning (current_function_decl, OPT_Wdangling_reference); > > + if (processing_template_decl) > + return saved_retval; > + > /* Actually copy the value returned into the appropriate location. */ > if (retval && retval != result) > { > diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-reference13.C b/gcc/testsuite/g++.dg/warn/Wdangling-reference13.C > new file mode 100644 > index 00000000000..bc09fbae22b > --- /dev/null > +++ b/gcc/testsuite/g++.dg/warn/Wdangling-reference13.C > @@ -0,0 +1,23 @@ > +// PR c++/109774 > +// { dg-do compile } > +// { dg-options "-Wdangling-reference" } > + > +int y; > + > +template > +int& get(const char& ) > +{ > + return y; > +} > + > +int& get2(const char&) > +{ > + return y; > +} > + > +int stuff(void) > +{ > + const int &h = get(0); // { dg-bogus "dangling reference" } > + const int &k = get2(0); // { dg-bogus "dangling reference" } > + return h+k; > +} > > base-commit: 94a311abf783de754f0f1b2d4c1f00a9788e795b