From patchwork Tue Aug 6 09:55:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1969413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=aEQcegtt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WdTGc75Qrz1yYD for ; Tue, 6 Aug 2024 19:56:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EE0E385700F for ; Tue, 6 Aug 2024 09:56:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by sourceware.org (Postfix) with ESMTPS id BF9CF385841C for ; Tue, 6 Aug 2024 09:55:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF9CF385841C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF9CF385841C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722938160; cv=none; b=OO9rTwvD/Xz93fxuaiHci6c4s8z2JeC/3l4Ks/ARcukSHajOa7t7tq9dWPdds+wGl2x1CmbXSXIWPHAr4KbLlNORpIh4t0QJJOqad9dpLtNV+SIy6OqLjHboVqiyBrBK3xq4rfl2dIJz3x3Upu4HULyJR9sxJWRZkd6jVGoqAHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722938160; c=relaxed/simple; bh=F/GAFYEnmeNnPfK/oXQ7ZVxihTk7Y/gxeOXvXeTTcM8=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=mBfuCoXLxZP+uVfOW8VMILioc0LDBg8mlSPOByGCYkJ2oxYMXWQYZYurWEnVAd332EkoX8FAKd+GvNFwlVarZT67s5p3J+osxWGWNouQ7grTrmweZ1JhTHU+PkQZhSg9H/131KVKcS6DfZOggwHy/GANZyewp/DzzV51WfBUM1Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-267b7ef154aso286516fac.0 for ; Tue, 06 Aug 2024 02:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722938158; x=1723542958; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7L1cAu6JnhUkeC+YMC8V6T+ng0EQ7CY2OoypPq6TDWQ=; b=aEQcegttgxd4/vwTrqm+nc4a2egiKjctf3K0eR5SEFuPW0fEhYqPJm4u1F96oxTCh1 WLftOaVEDwoyURNFJdg/SOhy1mF8aUzZIWscFG8XK69ZY+TS/b1R6HK2slvkkM/2IWLZ KswHQhJkc0m/rnXotmrLeAQG+BN64tpRH/tzjs1Dz2ZGsT78DVRHHNv4ATwpZAOnZLhx NwL48+aQ5bDC62VC+M689hrlyavJLm2XOo16kJ9zxO3gCm65a4a7ejYpOrk35lkxiq51 A8zhspq/S67stEhzjniERnhTFUdRptGRaQXeao+xQoSsQlx9xN0izcBCqGKwtsoIjE6d 09pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722938158; x=1723542958; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7L1cAu6JnhUkeC+YMC8V6T+ng0EQ7CY2OoypPq6TDWQ=; b=UDUOltKVSqyEIkVBOx7GlmE9dya+M/+elSrx1KIhfmpNHQDYBFhbiN+YmMq0P7A6qs hHMumoK4hCFKNPiiUTRPIbFzmtPnupmHkvc4FRDxNAVcmbCNNBFXP4CJodHhfVKPPRK9 n1GkNmRPbLYffnrckwejS4OYWvLx4cgzQBwlFC86bg3zUXqE3j8YKpw6+27+brm95VtU 1Fo5Mlpl0tHphlarEl9eRXOExQLZzjhGbaE+QisR+xFF3MdJ/lDCdOSx+B+AqSPz0oDu FhZJ1pf4oCf6bkbgzpQa7oTtqYDtb6axalBgmjT0S73mgbbAiJ2MdyI3vuximGWZsb0D gNmg== X-Gm-Message-State: AOJu0Yz1VXG+NpIO15C649nZ/c/HXicQU64k1GsD9ZWGRhWxXxClRCOu AV3RYIlhaTKwl/VS0uhU6b0CKCezqhT8PMmjBiwHPeF9LEcIzqdMKN5rFA== X-Google-Smtp-Source: AGHT+IGrbTEljjfdfKl477IqIki9euOPWytLZyMH27w3efS+lOLJbPpYo8IXu/jw8UZjIZDuSa/djw== X-Received: by 2002:a05:6870:a552:b0:25e:fb:af8c with SMTP id 586e51a60fabf-26891b0e0c4mr18703683fac.18.1722938157961; Tue, 06 Aug 2024 02:55:57 -0700 (PDT) Received: from Thaum. (110-174-164-242.static.tpgi.com.au. [110.174.164.242]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ec410c2sm6669603b3a.57.2024.08.06.02.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 02:55:57 -0700 (PDT) Message-ID: <66b1f32d.050a0220.e6a95.4239@mx.google.com> X-Google-Original-Message-ID: Date: Tue, 6 Aug 2024 19:55:52 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH] c++: Improve fixits for incorrect explicit instantiations MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- When forgetting the '<>' on an explicit specialisation, the suggested fixit hint suggests to add 'template <>', but naively applying will cause nonsense results like 'template template <> struct S {};'. Instead check if we're currently parsing an explicit instantiation, and if so inform about the issue (an instantiation cannot have a class body) and suggest a fixit of simply '<>' to create a specialisation instead. gcc/cp/ChangeLog: * parser.cc (cp_parser_class_head): Clarify error message for explicit instantiations. gcc/testsuite/ChangeLog: * g++.dg/template/explicit-instantiation9.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/parser.cc | 19 ++++++++++++++----- .../g++.dg/template/explicit-instantiation9.C | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/explicit-instantiation9.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index eb102dea829..4f2ad8201b7 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -27729,11 +27729,20 @@ cp_parser_class_head (cp_parser* parser, class_head_start_location, get_finish (type_start_token->location)); rich_location richloc (line_table, reported_loc); - richloc.add_fixit_insert_before (class_head_start_location, - "template <> "); - error_at (&richloc, - "an explicit specialization must be preceded by" - " %