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 792563858D38 for ; Fri, 10 Nov 2023 00:07:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 792563858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 792563858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699574828; cv=none; b=BEVdFqe1j6DPy8cUMcvGjy1bsgD1KICE0w2MhQQPGVnZhyctJa4BFN1OBK+JVGjq8DqkGj0p5EpZX5CqTZlkvn+I2ZtjyqRV3B40OL3gioPL6XVDr7Plo5ViZkKuPfPTg8BSDxBoo85/eqHrfHAYsaHQ/QTr+Ay07zKC4ayNKTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699574828; c=relaxed/simple; bh=+Ku0GMYjac2s3DSWx6S9bzJu6+IBXN4usB01hXp/AxA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=tYX65sxMJ3KmNgBf3JjXU5R6FGplUjWsJFLylB159DT3jqvQ38vfBWbE0uZV8/gPFW0yuzNkbGP3cT0eqWiYB6mWx3RQ0op4V6obpjHLcZzOXNwwlKSABGCi/1xIR4Pnh6mdB6GEwJqY5JOl+IHDjx0gPbRpG7Kfmbr81iqnkJo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699574826; 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=vDlCGPDoXIn+7KkTCIRCQPB6dxFae4bnHzFfhyhWgbM=; b=ibA8TQFhp/lcYhYKuaJ1ZBSIsI7Gqxo1+tSCNuUWlF2yUgn0MZnHToOqkFjE3bEMSgz2nU d53ZzKFdF6SG9P7aCv6kOre3XkbhzdlL4gRivxdsbz4uyqT3rJSfYETNJw9DPpRSXaK4O5 Qp/gMlpjgbs3954AIEFuuIn7OXnvyPM= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-QbQN9YjTP3uUOGHr4teaAQ-1; Thu, 09 Nov 2023 19:07:05 -0500 X-MC-Unique: QbQN9YjTP3uUOGHr4teaAQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-778a65923bdso160968985a.3 for ; Thu, 09 Nov 2023 16:07:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699574824; x=1700179624; 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=vDlCGPDoXIn+7KkTCIRCQPB6dxFae4bnHzFfhyhWgbM=; b=eMChg+8H+P7bfnVuj6r0udDDYyorttpUluePBdZPpAVhTRDiaBRpzvmWFO+S8UR1ZP ri+JDc3FVce8UKSruxO5oXSlOCe7DVCRD9rOFHPWdgVns2Jq4vGsho9jXmbUvO4EsvrH BFHNohm4gWkRQu+CnrN8uHlc5kjuDSJqjq88Qro3x2IP+i6x47QU/CkF9B3U3UUsItjS k8YFrY2QAUPnO8rtOuJf+Z9j93MWxNTzYGJXjloor/L9WGSIJDzbhaxsRrZWccpwXR5C NCdb+KD9Ot4xqrCk3TtLxvZpvIYWTSQ/OV4fWYwfXbB/6aPgIO/9AyLXXCOV/y6EGS2U Uwvw== X-Gm-Message-State: AOJu0Yxzzxnk4S+yExLJ0QqGrGemstjvZTDgz0LqBumCrw272sMnEjyj aaxBuuqdK2XW2JeJ90En9hWaYVvadXdhTl9fF61aMn7dOL0pu56Wb3DkAy7egrQ0/Uxqux8gOrL 2AyF8o8Rricu0HzY4DA== X-Received: by 2002:a05:620a:3727:b0:76c:b53b:8702 with SMTP id de39-20020a05620a372700b0076cb53b8702mr7656394qkb.26.1699574824577; Thu, 09 Nov 2023 16:07:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaqnoAq1f+ZlCRukADrHpUAYscIjmSG2KxF56XMa0hjazMmsiC5tNt8PnYfy/k/KM3ntKCDw== X-Received: by 2002:a05:620a:3727:b0:76c:b53b:8702 with SMTP id de39-20020a05620a372700b0076cb53b8702mr7656378qkb.26.1699574824309; Thu, 09 Nov 2023 16:07:04 -0800 (PST) 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 x4-20020a05620a14a400b007778503ebf4sm307568qkj.16.2023.11.09.16.07.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Nov 2023 16:07:03 -0800 (PST) Message-ID: <1c680274-040d-40d7-b998-b100084c0ba5@redhat.com> Date: Thu, 9 Nov 2023 19:07:03 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: fix parsing with auto(x) [PR112410] To: Marek Polacek , GCC Patches References: <20231109195835.429291-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20231109195835.429291-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=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 11/9/23 14:58, Marek Polacek wrote: > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > -- >8 -- > Here we are wrongly parsing > > int y(auto(42)); > > which uses the C++23 cast-to-prvalue feature, and initializes y to 42. > However, we were treating the auto as an implicit template parameter. > > Fixing the auto{42} case is easy, but when auto is followed by a (, > I found the fix to be much more involved. For instance, we cannot > use cp_parser_expression, because that can give hard errors. It's > also necessary to disambiguate 'auto(i)' as 'auto i', not a cast. > auto(), auto(int), auto(f)(int), auto(*), auto(i[]), auto(...), etc. > are all function declarations. We have to look at more than one > token to decide. Yeah, this is a most vexing parse problem. The code is synthesizing template parameters before we've resolved whether the auto is a decl-specifier or not. > In this fix, I'm (ab)using cp_parser_declarator, with member_p=false > so that it doesn't commit. But it handles even more complicated > cases as > > int fn (auto (*const **&f)(int) -> char); But it doesn't seem to handle the extremely vexing struct A { A(int,int); }; int main() { int a; A b(auto(a), 42); } I think we need to stop synthesizing immediately when we see RID_AUTO, and instead go back after we successfully parse a declaration and synthesize for any autos we saw along the way. :/ Jason