diff options
author | Marek Polacek <polacek@redhat.com> | 2020-04-04 18:09:53 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-05-20 17:00:06 -0400 |
commit | 4b38d56dbac6742b038551a36ec80200313123a1 (patch) | |
tree | 7d75adf2b43a0debeada1db1e232ef344aed5d74 /gcc/cp | |
parent | 38a4db21e12816c674406f33d8bc4d064d4211d7 (diff) | |
download | gcc-4b38d56dbac6742b038551a36ec80200313123a1.zip gcc-4b38d56dbac6742b038551a36ec80200313123a1.tar.gz gcc-4b38d56dbac6742b038551a36ec80200313123a1.tar.bz2 |
c++: C++20 DR 2237, disallow simple-template-id in cdtor.
This patch implements DR 2237 which says that a simple-template-id is
no longer valid as the declarator-id of a constructor or destructor;
see [diff.cpp17.class]#2. It is not explicitly stated but out-of-line
destructors with a simple-template-id are also meant to be ill-formed
now. (Out-of-line constructors like that are invalid since DR1435 I
think.) This change only applies to C++20; it is not a DR against C++17.
I'm not crazy about the diagnostic in constructors but ISTM that
cp_parser_constructor_declarator_p shouldn't print errors.
DR 2237
* parser.c (cp_parser_unqualified_id): Reject simple-template-id as
the declarator-id of a destructor.
(cp_parser_constructor_declarator_p): Reject simple-template-id as
the declarator-id of a constructor.
* g++.dg/DRs/dr2237.C: New test.
* g++.dg/parse/constructor2.C: Add dg-error for C++20.
* g++.dg/parse/dtor12.C: Likewise.
* g++.dg/parse/dtor4.C: Likewise.
* g++.dg/template/dtor4.C: Adjust dg-error.
* g++.dg/template/error34.C: Likewise.
* g++.old-deja/g++.other/inline15.C: Only run for C++17 and lesses.
* g++.old-deja/g++.pt/ctor2.C: Add dg-error for C++20.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/parser.c | 13 |
2 files changed, 20 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9ed4c58..cfe5cf0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,13 @@ 2020-05-20 Marek Polacek <polacek@redhat.com> + DR 2237 + * parser.c (cp_parser_unqualified_id): Reject simple-template-id as + the declarator-id of a destructor. + (cp_parser_constructor_declarator_p): Reject simple-template-id as + the declarator-id of a constructor. + +2020-05-20 Marek Polacek <polacek@redhat.com> + DR 2289 PR c++/94553 * cp-tree.h (SD_DECOMPOSITION): New flag. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a6a5d97..a8082d3 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6108,6 +6108,15 @@ cp_parser_unqualified_id (cp_parser* parser, return build_min_nt_loc (loc, BIT_NOT_EXPR, make_auto ()); } + /* DR 2237 (C++20 only): A simple-template-id is no longer valid as the + declarator-id of a constructor or destructor. */ + if (token->type == CPP_TEMPLATE_ID && cxx_dialect >= cxx20) + { + if (!cp_parser_simulate_error (parser)) + error_at (tilde_loc, "template-id not allowed for destructor"); + return error_mark_node; + } + /* If there was an explicit qualification (S::~T), first look in the scope given by the qualification (i.e., S). @@ -28628,7 +28637,9 @@ cp_parser_constructor_declarator_p (cp_parser *parser, cp_parser_flags flags, if (next_token->type != CPP_NAME && next_token->type != CPP_SCOPE && next_token->type != CPP_NESTED_NAME_SPECIFIER - && next_token->type != CPP_TEMPLATE_ID) + /* DR 2237 (C++20 only): A simple-template-id is no longer valid as the + declarator-id of a constructor or destructor. */ + && (next_token->type != CPP_TEMPLATE_ID || cxx_dialect >= cxx20)) return false; /* Parse tentatively; we are going to roll back all of the tokens |