From patchwork Sun Apr 12 13:48:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1269444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=yGxSHp03; dkim-atps=neutral Received: from sourceware.org (server2.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 ozlabs.org (Postfix) with ESMTPS id 490Y4d3yWrz9sSg for ; Sun, 12 Apr 2020 23:48:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5BDC385DC0A; Sun, 12 Apr 2020 13:48:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5BDC385DC0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586699323; bh=gMmH/P3MJAmGxuh/VjMwHX5SWUxkHvooSrTB+HFpjbU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yGxSHp03SeqQZ9LxkZKg6M0JJMtRr9yPnNRDhsKpxc/TbWr0YPf5ooViiVuEbhxlf oNtKH3tV4iGKmIHgn+qAWoWahV6UA9FoJcgV/r8tV0ufPxPwaiSTpUkQuOjVwUAmjJ jrKoFxbOv93Vw/RzE8z+F0KYKD1QzZ2gfzrJAS2g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id BE268385DC08 for ; Sun, 12 Apr 2020 13:48:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BE268385DC08 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-288-z9SRxlwpPLWW_3bQZXakNg-1; Sun, 12 Apr 2020 09:48:37 -0400 X-MC-Unique: z9SRxlwpPLWW_3bQZXakNg-1 Received: by mail-qv1-f72.google.com with SMTP id br11so5790483qvb.16 for ; Sun, 12 Apr 2020 06:48:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5/4uWaVMKF18xKtrvWCCwkejkFXEGkLAq+TwEesSVXM=; b=DNqOv6uAAc502NL7djQCB742ae+HKtl/DTnhHGYMH/PLUuJHrmUWPcrk9RfC67gje8 xLEVTRfaVCvZcruevnZINYcktFq9xC1NBzDhQzYL8R7pe9dEJrclw1LG022QKW8z2SoJ XyEH9s4hzzVO8Xyc6UCYiIYKqfIjVmfifdR0ZZIsyku+GWI3RSkzNfJ1bcX/kiHjulRk Ed6PG48IVkoAVDzm24ls5gH7wQZWlAgpo1Bnm8AC9X7tISRECH2LJsTPHpXGdtj3qPnA 7EPV+Lp18rHF9UfRQKx08yXNu2B4agLoE2HC6pXN25KL+qEU327GB7VPLJFHVkienejJ 2qcQ== X-Gm-Message-State: AGi0PuauqpIqe2Woso2MlvJ0vCZVwHSwnoIrZYmpiwwIK8MDAlKDjAwZ 3D3cr6XVibBuL+l2oIpRbHKTqC5Jd+yHSnQzoOAGnVRFELpXiClDjg2N4Kqh2gBT8xQy0+Ew5jj whdrGz3O3RkQy6xyOlA== X-Received: by 2002:a05:620a:11a4:: with SMTP id c4mr3700154qkk.409.1586699316279; Sun, 12 Apr 2020 06:48:36 -0700 (PDT) X-Google-Smtp-Source: APiQypIhcSyH8NROCRfVI5UJ8Es+VapDolyjCvhN2zPMZqjoF8F80qISqLOmGj1oaeessZuqiEHsdg== X-Received: by 2002:a05:620a:11a4:: with SMTP id c4mr3700141qkk.409.1586699316058; Sun, 12 Apr 2020 06:48:36 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id f1sm5758623qkl.72.2020.04.12.06.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2020 06:48:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Infinite diagnostic loop with decltype([]{}) [PR94521] Date: Sun, 12 Apr 2020 09:48:33 -0400 Message-Id: <20200412134833.2053141-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.0.106.g9fadedd637 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Patrick Palka via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" We are hitting a recursive loop when printing the signature of a function containing a decltype([]{}) type. The loop is dump_function_decl -> dump_substitution -> dump_template_bindings -> dump_type -> dump_aggr_type -> dump_scope -> dump_function_decl and we loop because dump_template_bindings wants to print the resolved type of decltype([]{}) (i.e. just a lambda type), so it calls dump_aggr_type, which wants to print the function scope of the lambda type. But the function scope of the lambda type is the function which we're in the middle of printing. This patch breaks the loop by passing TFF_NO_FUNCTION_ARGUMENTS to dump_function_decl from dump_scope, so that we avoid recursing into dump_substitution and ultimately looping. This also means we no longer print a "[with ...]" clause when printing a function template scope, and we instead just print its template argument list in a more natural way, e.g. instead of foo(int, char) [with T=bool]::x we would now print foo::x which seems like an improvement on its own. The full signature of the function 'spam' in the below testcase is now void spam(decltype ()*) [with T = int; decltype () = spam::] Successfully bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to commit? gcc/cp/ChangeLog: PR c++/94521 * error.c (dump_scope): Pass TFF_NO_FUNCTION_ARGUMENTS to dump_function_decl when printing a function template instantiation as a scope. gcc/testsuite/ChangeLog: PR c++/94521 * g++.dg/cpp2a/lambda-uneval12.C: New test. --- gcc/cp/error.c | 2 ++ gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 61d1218dc90..98c163db572 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -211,6 +211,8 @@ dump_scope (cxx_pretty_printer *pp, tree scope, int flags) } else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL) { + if (DECL_USE_TEMPLATE (scope)) + f |= TFF_NO_FUNCTION_ARGUMENTS; dump_function_decl (pp, scope, f); pp_cxx_colon_colon (pp); } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C new file mode 100644 index 00000000000..24d2e701e44 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C @@ -0,0 +1,13 @@ +// PR c++/94521 +// { dg-do compile { target c++2a } } + +template +void spam(decltype([]{}) *s) +{ + static_assert(__is_same(int, decltype(s))); // { dg-error "static assertion failed" } +} + +void foo() +{ + spam(nullptr); +}