public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113929] New: GCC accepts template<this auto>
@ 2024-02-15 14:55 hewillk at gmail dot com
2024-02-15 16:45 ` [Bug c++/113929] " jakub at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: hewillk at gmail dot com @ 2024-02-15 14:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113929
Bug ID: 113929
Summary: GCC accepts template<this auto>
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
This is the sibling of Bug 113788.
template<this auto> struct S {} ;
S<0> s{};
https://godbolt.org/z/GbdqW9zee
Thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/113929] GCC accepts template<this auto>
2024-02-15 14:55 [Bug c++/113929] New: GCC accepts template<this auto> hewillk at gmail dot com
@ 2024-02-15 16:45 ` jakub at gcc dot gnu.org
2024-02-16 16:43 ` cvs-commit at gcc dot gnu.org
2024-02-16 16:44 ` jakub at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-15 16:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113929
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is IMHO different, because the grammar is:
template-parameter:
type-parameter
parameter-declaration
parameter-declaration:
attribute-specifier-seq[opt] this[opt] decl-specifier-seq declarator
attribute-specifier-seq[opt] decl-specifier-seq declarator =
initializer-clause
attribute-specifier-seq[opt] this[opt] decl-specifier-seq
abstract-declarator[opt]
attribute-specifier-seq[opt] decl-specifier-seq abstract-declarator[opt] =
initializer-clause
So, unlike the other cases, the grammar allows this specifier in there, just
https://eel.is/c++draft/dcl.fct#6 says it is invalid, because it is not the
first parameter-declaration of a parameter-declaration-list (because it is a
parameter-declaration of a template-parameter-list instead).
I'd go with (on top of PR113802 fix):
2024-02-15 Jakub Jelinek <jakub@redhat.com>
PR c++/113929
* parser.cc (cp_parser_parameter_declaration): Diagnose this specifier
on template parameter declaration.
* g++.dg/parse/pr113929.C: New test.
--- gcc/cp/parser.cc.jj 2024-02-15 17:33:11.641453437 +0100
+++ gcc/cp/parser.cc 2024-02-15 17:40:29.592447265 +0100
@@ -25724,8 +25724,15 @@ cp_parser_parameter_declaration (cp_pars
for a C-style variadic function. */
token = cp_lexer_peek_token (parser->lexer);
- bool const xobj_param_p
+ bool xobj_param_p
= decl_spec_seq_has_spec_p (&decl_specifiers, ds_this);
+ if (xobj_param_p && template_parm_p)
+ {
+ error_at (decl_specifiers.locations[ds_this],
+ "%<this%> specifier in template parameter declaration");
+ xobj_param_p = false;
+ decl_specifiers.locations[ds_this] = 0;
+ }
bool diag_xobj_parameter_pack = false;
if (xobj_param_p && (declarator && declarator->parameter_pack_p))
--- gcc/testsuite/g++.dg/parse/pr113929.C.jj 2024-02-15 17:43:18.500129688
+0100
+++ gcc/testsuite/g++.dg/parse/pr113929.C 2024-02-15 17:42:54.564458109
+0100
@@ -0,0 +1,7 @@
+// PR c++/113929
+// { dg-do compile }
+
+template <this int C> // { dg-error "'this' specifier in template
parameter declaration" }
+struct S {};
+template <int N, this int C> // { dg-error "'this' specifier in template
parameter declaration" }
+struct T {};
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/113929] GCC accepts template<this auto>
2024-02-15 14:55 [Bug c++/113929] New: GCC accepts template<this auto> hewillk at gmail dot com
2024-02-15 16:45 ` [Bug c++/113929] " jakub at gcc dot gnu.org
@ 2024-02-16 16:43 ` cvs-commit at gcc dot gnu.org
2024-02-16 16:44 ` jakub at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-16 16:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113929
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:5286b0761b5dfac4348d1c5bfdcc162a66f338ee
commit r14-9033-g5286b0761b5dfac4348d1c5bfdcc162a66f338ee
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Feb 16 17:42:32 2024 +0100
c++: Diagnose this specifier on template parameters [PR113929]
For template parameters, the optional this specifier is in the grammar
template-parameter-list -> template-parameter -> parameter-declaration,
just [dcl.fct/6] says that it is only valid in parameter-list of certain
functions. So, unlike the case of decl-specifier-seq used in non-terminals
other than parameter-declaration, I think it is better not to fix this
by
cp_parser_decl_specifier_seq (parser,
- flags | CP_PARSER_FLAGS_PARAMETER,
+ flags | (template_parameter_p ? 0
+ : CP_PARSER_FLAGS_PARAMETER),
&decl_specifiers,
&declares_class_or_enum);
which would be pretending it isn't in the grammar, but by diagnosing it
separately, which is what the following patch does.
2024-02-16 Jakub Jelinek <jakub@redhat.com>
PR c++/113929
* parser.cc (cp_parser_parameter_declaration): Diagnose this
specifier
on template parameter declaration.
* g++.dg/parse/pr113929.C: New test.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/113929] GCC accepts template<this auto>
2024-02-15 14:55 [Bug c++/113929] New: GCC accepts template<this auto> hewillk at gmail dot com
2024-02-15 16:45 ` [Bug c++/113929] " jakub at gcc dot gnu.org
2024-02-16 16:43 ` cvs-commit at gcc dot gnu.org
@ 2024-02-16 16:44 ` jakub at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-16 16:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113929
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-16 16:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-15 14:55 [Bug c++/113929] New: GCC accepts template<this auto> hewillk at gmail dot com
2024-02-15 16:45 ` [Bug c++/113929] " jakub at gcc dot gnu.org
2024-02-16 16:43 ` cvs-commit at gcc dot gnu.org
2024-02-16 16:44 ` jakub at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).