From patchwork Mon Nov 15 07:53:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1555186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=szk9/Rum; dkim-atps=neutral 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=) Received: from sourceware.org (ip-8-43-85-97.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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Ht1gJ4dkpz9s1l for ; Mon, 15 Nov 2021 18:54:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A1D03858433 for ; Mon, 15 Nov 2021 07:54:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A1D03858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636962874; bh=PuXsBWXjonQ0bCUdKmBAwhe1T54TQdNN/wcf/xmAaaY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=szk9/Rum0qZYKI3U2arVkBEWuLdRdmdwURfGd+yt7ZJxSGXvm3H2VaGQTeYSaqnY2 ByhMG0uEWTZqG0gf1bQGeWxZI9qSK1SnUTyECY2tsYM/cyoqhh70kHdM8zSvUcTH/2 uT3lyIrOonFcrbEedg6fZMGJc+Y8dEiv6fM8efUs= 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 1D1323858428 for ; Mon, 15 Nov 2021 07:53:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1D1323858428 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-58-4FGtK-v9P4OZrOhNWJhByA-1; Mon, 15 Nov 2021 02:53:11 -0500 X-MC-Unique: 4FGtK-v9P4OZrOhNWJhByA-1 Received: by mail-qk1-f197.google.com with SMTP id w13-20020a05620a0e8d00b0045fad6245e8so10462113qkm.8 for ; Sun, 14 Nov 2021 23:53:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=PuXsBWXjonQ0bCUdKmBAwhe1T54TQdNN/wcf/xmAaaY=; b=euURBfuJ/rxZuGLY4nEKDksX8aLQahzOxvGvpaJBE/cmPC6ddyLkcOomJyxXn/AXgf DRlpwA5afp04VNubWv9UjL95ONbYFpii/RqeQXSg41AoZnqUOXh3QQO1s/ubjTy0AY8X RIvB6iaMzWJ67jIDuef59MpRQ8vgien650xUn2D/k52LDdva7T1G2kcysr32rrvAISkm 7U+ZE5eFw6FWGbr4W5VH7rmSQKUKOMIB7Gts9lzSWHNAlSpp3rNwEUDaaYygFxiTcx+3 p1ipgWkGSAbi2K8hYg0dzvJK6RQiPtRI1PmUf6J/bOzM1cwia3Y0I7kWAaXUSGF0qPCU X7hQ== X-Gm-Message-State: AOAM530+6Tiv9rLNIHme8HiPIjaTqbyJqo7vO9sFJaETnvxXmGiD0G62 hl6Kl2VLw/nUBNDezelXyBg8Kv3M8/m1zeNWA4Cwf/UVwgM7jwgeufQvEc0irj5Npb5elM/O51t LlMXW86KqusWqFQtDNd6I3B+UVTQqBKnln3DFfbFzR45qZ3ak9G0trxUOZi+VSLYbKg== X-Received: by 2002:ac8:19:: with SMTP id a25mr38204690qtg.360.1636962790720; Sun, 14 Nov 2021 23:53:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDfwBa8nLlUk2ej/zQiBhoYgr22ynR1kp/uia5iTuKYhiN9p7AuLoPhoo1J+82l9k0dbI0dQ== X-Received: by 2002:ac8:19:: with SMTP id a25mr38204666qtg.360.1636962790416; Sun, 14 Nov 2021 23:53:10 -0800 (PST) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id s2sm1215747qtw.22.2021.11.14.23.53.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 23:53:09 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: location of lambda object and conversion call Date: Mon, 15 Nov 2021 02:53:06 -0500 Message-Id: <20211115075306.3355557-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_H2, 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Two things that had poor location info: we weren't giving the TARGET_EXPR for a lambda object any location, and the call to a conversion function was getting whatever input_location happened to be. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * call.c (perform_implicit_conversion_flags): Use the location of the argument. * lambda.c (build_lambda_object): Set location on the TARGET_EXPR. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-switch.C: Adjust expected location. --- gcc/cp/call.c | 6 +++++- gcc/cp/lambda.c | 7 +++---- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) base-commit: 37326651b439bac55d96fb5a43f4daf25e401eda diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 01ac114a62c..4ee21c7bdbd 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -12549,7 +12549,11 @@ perform_implicit_conversion_flags (tree type, tree expr, IMPLICIT_CONV_EXPR_BRACED_INIT (expr) = true; } else - expr = convert_like (conv, expr, complain); + { + /* Give a conversion call the same location as expr. */ + iloc_sentinel il (loc); + expr = convert_like (conv, expr, complain); + } /* Free all the conversions we allocated. */ obstack_free (&conversion_obstack, p); diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 2e9d38bbe83..f68c68ca16e 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -57,14 +57,13 @@ build_lambda_object (tree lambda_expr) - cp_parser_functional_cast */ vec *elts = NULL; tree node, expr, type; - location_t saved_loc; if (processing_template_decl || lambda_expr == error_mark_node) return lambda_expr; /* Make sure any error messages refer to the lambda-introducer. */ - saved_loc = input_location; - input_location = LAMBDA_EXPR_LOCATION (lambda_expr); + location_t loc = LAMBDA_EXPR_LOCATION (lambda_expr); + iloc_sentinel il (loc); for (node = LAMBDA_EXPR_CAPTURE_LIST (lambda_expr); node; @@ -117,10 +116,10 @@ build_lambda_object (tree lambda_expr) type = LAMBDA_EXPR_CLOSURE (lambda_expr); CLASSTYPE_NON_AGGREGATE (type) = 0; expr = finish_compound_literal (type, expr, tf_warning_or_error); + protected_set_expr_location (expr, loc); CLASSTYPE_NON_AGGREGATE (type) = 1; out: - input_location = saved_loc; return expr; } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C index d05c9760709..e417967a17e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C @@ -16,11 +16,11 @@ main () break; // { dg-error "break" } } }; - l = []() + l = []() // { dg-warning "statement will never be executed" } { case 3: // { dg-error "case" } break; // { dg-error "break" } - }; // { dg-warning "statement will never be executed" } + }; } } }