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 81C4A3858298 for ; Wed, 7 Sep 2022 17:36:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 81C4A3858298 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662572210; 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; bh=JX9OG0/7y/7e/uvI0gqKBl1hlZE0MpudIyDDuaBNuPo=; b=fW21fgQCPuyeEyKZsFugbdvSmnPqGv7gSQg23U7deyAqMIRSxqEvqpK6F4ieGDozrmPS2d cirbqKkTSgsZSVyKfz1ecjNRJzXTu/RSturrMoY+N7Rvo/3dIVSElx7OyFHKws5q/xgXks M5xZRBSk+XLv2uNBg8cKzrntuTI+f9w= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-88-VX-8bLuwNN-BBtgi3c4dBQ-1; Wed, 07 Sep 2022 13:36:49 -0400 X-MC-Unique: VX-8bLuwNN-BBtgi3c4dBQ-1 Received: by mail-qv1-f69.google.com with SMTP id y16-20020a0cec10000000b004a5df9e16c6so6497023qvo.1 for ; Wed, 07 Sep 2022 10:36:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=JX9OG0/7y/7e/uvI0gqKBl1hlZE0MpudIyDDuaBNuPo=; b=hIyG+14g5QWv8JCineu0qhJ1PSFk5eFLRZlLtbTF3yqFMG71g8GoOyA3aPTD342xKD AxYwInBPAJFmQBLTyoWNRg1/S1uNqqxcOVB3gxMc/zTaHTrEdipPaQ+TvWnGfgqZ8XBA 5TYBSun3SDF8ZudtOGmURrwwdmSjGjeTTwBhhCeV+Q/s6P5zeAYMhpomAVjsufGA60PP kfHrtKTtNsV9WhXMCv9wHjpHmXi5v3FyAcfeJirx0m9ux7ooqaZO/AbZsH5EdYWW3lyJ bJ9giBIPILCjPoUsQjcBaq3rxZYV38PthMGKbtWtfFu51RdYmFXl5Yz8ayTqbC/nw19U MOqw== X-Gm-Message-State: ACgBeo3bsFQ4PDCmPHm6GRMT8SrlV+Bzk9krrIlvP0CrKU9hqindsd7J qfcER4UczHitMt1hRopM2yOL4crdKJBOJk/seqpx5KGCpB+2YJJ23Jv0ub5TFuAYLD+Bj1iCq5C D+XSmRQvitZPp+bq151rl9yLdutdVPd2aDkC8LBXTVKpFKDPLQksHY8hTbgDqazD28w== X-Received: by 2002:a05:620a:12fb:b0:6bb:4ba4:aa85 with SMTP id f27-20020a05620a12fb00b006bb4ba4aa85mr3586916qkl.704.1662572208304; Wed, 07 Sep 2022 10:36:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR6zRWozCtAGe7oJ+4Y7oAoJAjGVBmjipLrM7+Dgfs4+Cv+lwJ0dBt7qZDXGvlw8Q8On3fXgrQ== X-Received: by 2002:a05:620a:12fb:b0:6bb:4ba4:aa85 with SMTP id f27-20020a05620a12fb00b006bb4ba4aa85mr3586892qkl.704.1662572207810; Wed, 07 Sep 2022 10:36:47 -0700 (PDT) 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 s11-20020a05620a29cb00b006bad20a6cfesm15296153qkp.102.2022.09.07.10.36.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 10:36:47 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: diagnostic for template placeholder in parm [PR106793] Date: Wed, 7 Sep 2022 13:36:45 -0400 Message-Id: <20220907173645.1716251-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.2 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,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: Talking about the declarator form doesn't help when fixing that would get you a different error about placeholders not being valid in a parameter. This also adds a <> fixit, which isn't enough for most templates, but is a start. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/106793 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Improve placeholder diagnostics. * parser.cc (cp_parser_type_id_1): Add fixit. gcc/testsuite/ChangeLog: * g++.dg/cpp23/auto-array2.C: Adjust. * g++.dg/cpp1z/class-deduction113.C: New test. --- gcc/cp/decl.cc | 30 ++++++++++++------- gcc/cp/parser.cc | 7 +++-- .../g++.dg/cpp1z/class-deduction113.C | 5 ++++ gcc/testsuite/g++.dg/cpp23/auto-array2.C | 4 +-- 4 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction113.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 6d20765f40c..4665a29a24d 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -12407,14 +12407,20 @@ grokdeclarator (const cp_declarator *declarator, if (cxx_dialect >= cxx17 && type && is_auto (type) && innermost_code != cdk_function + /* Placeholder in parm gets a better error below. */ + && !(decl_context == PARM || decl_context == CATCHPARM) && id_declarator && declarator != id_declarator) if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type)) - { - error_at (typespec_loc, "template placeholder type %qT must be followed " - "by a simple declarator-id", type); - inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl); - type = error_mark_node; - } + { + auto_diagnostic_group g; + gcc_rich_location richloc (typespec_loc); + richloc.add_fixit_insert_after ("<>"); + error_at (&richloc, "missing template argument list after %qE; " + "for deduction, template placeholder must be followed " + "by a simple declarator-id", tmpl); + inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl); + type = error_mark_node; + } staticp = 0; inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline); @@ -12892,6 +12898,7 @@ grokdeclarator (const cp_declarator *declarator, { if (!funcdecl_p || !dguide_name_p (unqualified_id)) { + auto_diagnostic_group g; error_at (typespec_loc, "deduced class " "type %qD in function return type", DECL_NAME (tmpl)); @@ -13837,12 +13844,15 @@ grokdeclarator (const cp_declarator *declarator, else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node)) { auto_diagnostic_group g; - error_at (typespec_loc, - "class template placeholder %qE not permitted " - "in this context", c); + gcc_rich_location richloc (typespec_loc); + richloc.add_fixit_insert_after ("<>"); + error_at (&richloc, + "missing template argument list after %qE; template " + "placeholder not permitted in parameter", c); if (decl_context == PARM && cxx_dialect >= cxx20) - inform (typespec_loc, "use % for an " + inform (typespec_loc, "or use % for an " "abbreviated function template"); + inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c); } else error_at (typespec_loc, diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 289c2142e45..841ba6ed997 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -24397,8 +24397,11 @@ cp_parser_type_id_1 (cp_parser *parser, cp_parser_flags flags, location_t loc = type_specifier_seq.locations[ds_type_spec]; if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node)) { - error_at (loc, "missing template arguments after %qT", - auto_node); + auto_diagnostic_group g; + gcc_rich_location richloc (loc); + richloc.add_fixit_insert_after ("<>"); + error_at (&richloc, "missing template arguments after %qE", + tmpl); inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl); } diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction113.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction113.C new file mode 100644 index 00000000000..8f6908e2746 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction113.C @@ -0,0 +1,5 @@ +// PR c++/106793 + +template struct A { A(T); }; +template void f(A *a); // { dg-error "placeholder.*parameter" "" { target c++17 } } +// { dg-error "" "" { target c++14_down } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp23/auto-array2.C b/gcc/testsuite/g++.dg/cpp23/auto-array2.C index 06431685b30..3fc2eae3cea 100644 --- a/gcc/testsuite/g++.dg/cpp23/auto-array2.C +++ b/gcc/testsuite/g++.dg/cpp23/auto-array2.C @@ -5,7 +5,7 @@ template struct A { A(); }; A a[3]; auto (*p)[3] = &a; A (*p2)[3] = &a; -A (*p3)[3] = &a; // { dg-error "template placeholder type" } +A (*p3)[3] = &a; // { dg-error "template placeholder" } auto (&r)[3] = a; A (&r2)[3] = a; -A (&r3)[3] = a; // { dg-error "template placeholder type" } +A (&r3)[3] = a; // { dg-error "template placeholder" } base-commit: a961ad1b13b9c294d4565344912b8e35ba71b369 -- 2.31.1