From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55835 invoked by alias); 7 Sep 2018 12:41:18 -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 55824 invoked by uid 89); 7 Sep 2018 12:41:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=1200, checkc, sk:DECL_SO, sk:decl_so X-HELO: mail-oi0-f67.google.com Received: from mail-oi0-f67.google.com (HELO mail-oi0-f67.google.com) (209.85.218.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Sep 2018 12:41:16 +0000 Received: by mail-oi0-f67.google.com with SMTP id r69-v6so26959731oie.3 for ; Fri, 07 Sep 2018 05:41:16 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a8a:9c6:0:0:0:0:0 with HTTP; Fri, 7 Sep 2018 05:40:53 -0700 (PDT) In-Reply-To: <20180813222438.GR4317@redhat.com> References: <20180703185805.GH5927@redhat.com> <20180723204912.GH29486@redhat.com> <20180809205940.GJ4317@redhat.com> <20180811141350.GL4317@redhat.com> <20180813222438.GR4317@redhat.com> From: Jason Merrill Date: Fri, 07 Sep 2018 12:41:00 -0000 Message-ID: Subject: Re: C++ PATCH for c++/57891, narrowing conversions in non-type template arguments To: Marek Polacek Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00432.txt.bz2 On Mon, Aug 13, 2018 at 11:24 PM, Marek Polacek wrote: > On Mon, Aug 13, 2018 at 10:14:21PM +1200, Jason Merrill wrote: >> >> >> > --- gcc/cp/decl.c >> >> >> > +++ gcc/cp/decl.c >> >> >> > @@ -9581,7 +9581,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) >> >> >> > { >> >> >> > tree folded = cp_fully_fold (size); >> >> >> > if (TREE_CODE (folded) == INTEGER_CST) >> >> >> > - pedwarn (location_of (size), OPT_Wpedantic, >> >> >> > + pedwarn (input_location, OPT_Wpedantic, >> >> >> >> >> >> It should work to use location_of (osize) here. >> >> > >> >> > I dropped this hunk altogether. Because location_of will use >> >> > DECL_SOURCE_LOCATION for DECLs, the error message will point to the declaration >> >> > itself, not the use. I don't really care either way. >> >> >> >> We want the message to point to the use, which location_of (osize) >> >> will provide, since it should still have a location wrapper around a >> >> DECL. >> > >> > location_of (osize) is actually the same as location_of (size) so that didn't >> > change anything. >> >> Hunh, that's strange. Why isn't osize the unfolded expression? Where >> is the location wrapper getting stripped? > > I actually see that it didn't have the location wrapper at the start. > The array bound is parsed in cp_parser_direct_new_declarator, and we > never called maybe_wrap_with_location to add the wrapper. I don't know > where that's supposed to happen. > > This quick hack works > > --- a/gcc/cp/parser.c > +++ b/gcc/cp/parser.c > @@ -8681,6 +8681,7 @@ cp_parser_direct_new_declarator (cp_parser* parser) > cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE); > > /* Add this bound to the declarator. */ > + expression = maybe_wrap_with_location (expression, token->location); > declarator = make_array_declarator (declarator, expression); > > /* If the next token is not a `[', then there are no more > > but that feels too ad-hoc and beyond the scope of this fix. > >> > The code below uses input_location which is why I went with >> > it in the first place. So, should I change this to input_location? >> >> I suppose so. > > Here's the version with input_location. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2018-08-13 Marek Polacek > > PR c++/57891 > * call.c (struct conversion): Add check_narrowing_const_only. > (build_converted_constant_expr): Set check_narrowing and > check_narrowing_const_only. Give error if expr is error node. > (convert_like_real): Pass it to check_narrowing. > * cp-tree.h (check_narrowing): Add a default parameter. > * decl.c (compute_array_index_type): Use input_location instead of > location_of. > * pt.c (convert_nontype_argument): Return NULL_TREE if tf_error. > * typeck2.c (check_narrowing): Don't warn for instantiation-dependent > expressions. Call maybe_constant_value instead of > fold_non_dependent_expr. Don't mention { } in diagnostic. Only check > narrowing for constants if CONST_ONLY. This seems to have broken cpp1z/direct-enum-init1.C with -std=c++17 and above; please use make check-c++-all (or set GXX_TESTSUITE_STDS=98,11,14,17,2a) to test C++ patches in all conformance modes. Jason