From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91378 invoked by alias); 25 Jan 2019 15:05:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 91368 invoked by uid 89); 25 Jan 2019 15:05:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy= X-HELO: mail-qk1-f176.google.com Received: from mail-qk1-f176.google.com (HELO mail-qk1-f176.google.com) (209.85.222.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Jan 2019 15:05:12 +0000 Received: by mail-qk1-f176.google.com with SMTP id 68so5540850qke.9 for ; Fri, 25 Jan 2019 07:05:12 -0800 (PST) Return-Path: Received: from [192.168.1.115] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id p42sm71865256qte.8.2019.01.25.07.05.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 07:05:09 -0800 (PST) Subject: Re: C++ PATCH for c++/78244 - narrowing conversion in template not detected, part 2 To: Marek Polacek Cc: GCC Patches References: <20190117190921.GM19569@redhat.com> <4958169a-e8c8-4ca0-6f99-ce360b4834d5@redhat.com> <20190118141207.GN19569@redhat.com> <20190122211021.GC26714@redhat.com> <33c9ff91-1aff-d328-7349-767b196eaecf@redhat.com> <20190123175735.GF26714@redhat.com> <20190125001757.GH26714@redhat.com> From: Jason Merrill Message-ID: <26ab4b9a-c572-7a9f-7fcd-18bcdc7e3c1d@redhat.com> Date: Fri, 25 Jan 2019 15:06:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20190125001757.GH26714@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg01511.txt.bz2 On 1/24/19 7:17 PM, Marek Polacek wrote: > On Wed, Jan 23, 2019 at 03:34:04PM -0500, Jason Merrill wrote: >> On Wed, Jan 23, 2019 at 12:57 PM Marek Polacek wrote: >>> >>> On Wed, Jan 23, 2019 at 09:00:36AM -0500, Jason Merrill wrote: >>>> I was talking about digest_init, not reshape_init. digest_init calls >>>> convert_for_initialization. >>> >>> /facepalm >>> >>> So yes, digest_init calls convert_for_initialization which will end up >>> calling perform_implicit_conversion_flags which could call convert_like_real >>> where the narrowing warnings are given, but it doesn't, we go to this case: >>> >>> else if (processing_template_decl && conv->kind != ck_identity) >>> { >>> /* In a template, we are only concerned about determining the >>> type of non-dependent expressions, so we do not have to >>> perform the actual conversion. But for initializers, we >>> need to be able to perform it at instantiation >>> (or instantiate_non_dependent_expr) time. */ >>> expr = build1 (IMPLICIT_CONV_EXPR, type, expr); >>> >>> finish_decltype_type throws away the expression because it's not dependent, and >>> only uses its type. So narrowing remains undetected. Not sure if I should mess >>> with perform_implicit_conversion_flags. >> >> Let's try that; this is a situation where the comment is incorrect. >> Perhaps just call check_narrowing here if appropriate, rather than go >> through the whole conversion machinery. > > I have not been successful. > > First, I modified perform_implicit_conversion_flags to go the convert_like > route when dealing with something non-dependent. That breaks e.g. in > build_value_init: > 346 /* The AGGR_INIT_EXPR tweaking below breaks in templates. */ > 347 gcc_assert (!processing_template_decl > 348 || (SCALAR_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)); > Even if I restrict the convert_like way for non-dependent exprs in a template > for scalars, it still breaks elsewhere, e.g. constexpr-template3.C where it > complains about taking the address of an rvalue. > > Second, I added check_narrowing to the processing_template_decl case in > perform_implicit_conversion_flags. That works except it breaks > constexpr-inst1.C -- we no longer get the error. That's because currently > check_narrowing in finish_compound_literal calls maybe_constant_init, which > calls instantiate_constexpr_fns and we get the desired diagnostic. But if > I move check_narrowing to perform_implicit_conversion_flags, we no longer > call it in this case -- processing_template_decl is 0 so we call convert_like > but that doesn't do the trick. > > So, back to the patch that leaves check_narrowing in finish_compound_literal? That patch still needs a test for the aggregate case. Jason