aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-04-04 18:09:53 -0400
committerMarek Polacek <polacek@redhat.com>2020-05-20 17:00:06 -0400
commit4b38d56dbac6742b038551a36ec80200313123a1 (patch)
tree7d75adf2b43a0debeada1db1e232ef344aed5d74 /gcc
parent38a4db21e12816c674406f33d8bc4d064d4211d7 (diff)
downloadgcc-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')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/parser.c13
-rw-r--r--gcc/testsuite/ChangeLog12
-rw-r--r--gcc/testsuite/g++.dg/DRs/dr2237.C18
-rw-r--r--gcc/testsuite/g++.dg/parse/constructor2.C4
-rw-r--r--gcc/testsuite/g++.dg/parse/dtor12.C2
-rw-r--r--gcc/testsuite/g++.dg/parse/dtor4.C2
-rw-r--r--gcc/testsuite/g++.dg/template/dtor4.C2
-rw-r--r--gcc/testsuite/g++.dg/template/error34.C10
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/inline15.C2
-rw-r--r--gcc/testsuite/g++.old-deja/g++.pt/ctor2.C2
11 files changed, 62 insertions, 13 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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9e437af..e9d334d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,17 @@
2020-05-20 Marek Polacek <polacek@redhat.com>
+ DR 2237
+ * 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.
+
+2020-05-20 Marek Polacek <polacek@redhat.com>
+
DR 2289
PR c++/94553
* g++.dg/cpp1z/decomp52.C: New test.
diff --git a/gcc/testsuite/g++.dg/DRs/dr2237.C b/gcc/testsuite/g++.dg/DRs/dr2237.C
new file mode 100644
index 0000000..f3d6d11
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2237.C
@@ -0,0 +1,18 @@
+// DR 2237 - Can a template-id name a constructor?
+
+template<class T>
+struct X {
+ X<T>(); // { dg-error "expected" "" { target c++20 } }
+ X(int); // OK, injected-class-name used
+ ~X<T>(); // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
+};
+
+// ill-formed since DR1435
+template<typename T> X<T>::X<T>() {} // { dg-error "names the constructor|as no template constructors" }
+template<typename T> X<T>::~X<T>() {} // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
+
+struct Q {
+ // ill-formed since DR1435
+ template<typename T> friend X<T>::X<T>(); // { dg-error "names the constructor|as no template constructors" }
+ template<typename T> friend X<T>::~X<T>(); // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
+};
diff --git a/gcc/testsuite/g++.dg/parse/constructor2.C b/gcc/testsuite/g++.dg/parse/constructor2.C
index e514e93..d620f41 100644
--- a/gcc/testsuite/g++.dg/parse/constructor2.C
+++ b/gcc/testsuite/g++.dg/parse/constructor2.C
@@ -5,7 +5,7 @@ class T
{
public:
T(short,short f=0) {}
- T<TClass>(int f) {}
- T<TClass>(int f=0,const char* b=0) {}
+ T<TClass>(int f) {} // { dg-error "expected" "" { target c++20 } }
+ T<TClass>(int f=0,const char* b=0) {} // { dg-error "expected" "" { target c++20 } }
};
diff --git a/gcc/testsuite/g++.dg/parse/dtor12.C b/gcc/testsuite/g++.dg/parse/dtor12.C
index 1acdfa3..dda7388 100644
--- a/gcc/testsuite/g++.dg/parse/dtor12.C
+++ b/gcc/testsuite/g++.dg/parse/dtor12.C
@@ -2,5 +2,5 @@
template <class T> class a
{
- ~a<T>();
+ ~a<T>(); // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
};
diff --git a/gcc/testsuite/g++.dg/parse/dtor4.C b/gcc/testsuite/g++.dg/parse/dtor4.C
index 729ee2f..1a1a845 100644
--- a/gcc/testsuite/g++.dg/parse/dtor4.C
+++ b/gcc/testsuite/g++.dg/parse/dtor4.C
@@ -7,4 +7,4 @@ template <int N> struct X {
};
template <int N>
-X<N>::~X<N>(){}
+X<N>::~X<N>(){} // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
diff --git a/gcc/testsuite/g++.dg/template/dtor4.C b/gcc/testsuite/g++.dg/template/dtor4.C
index 4f277b2..917681f 100644
--- a/gcc/testsuite/g++.dg/template/dtor4.C
+++ b/gcc/testsuite/g++.dg/template/dtor4.C
@@ -5,5 +5,5 @@
template<int> struct A
{
- ~A<0>(); // { dg-error "parse error|declaration" }
+ ~A<0>(); // { dg-error "parse error|declaration|template-id" }
};
diff --git a/gcc/testsuite/g++.dg/template/error34.C b/gcc/testsuite/g++.dg/template/error34.C
index d0cbcae..ab688d9 100644
--- a/gcc/testsuite/g++.dg/template/error34.C
+++ b/gcc/testsuite/g++.dg/template/error34.C
@@ -3,27 +3,27 @@
template<typename T> struct A
{
- A<__builtin_offsetof(T, x)>(); // { dg-error "type/value mismatch|offsetof\\(T, x\\)" }
+ A<__builtin_offsetof(T, x)>(); // { dg-error "type/value mismatch|offsetof\\(T, x\\)|expected" }
};
template<typename T> struct B
{
- B<__builtin_offsetof(T, x.y)>(); // { dg-error "type/value mismatch|offsetof\\(T, x.y\\)" }
+ B<__builtin_offsetof(T, x.y)>(); // { dg-error "type/value mismatch|offsetof\\(T, x.y\\)|expected" }
};
template<typename T> struct C
{
- C<__builtin_offsetof(T, x[6])>(); // { dg-error "type/value mismatch|offsetof\\(T, x\\\[6\\\]\\)" }
+ C<__builtin_offsetof(T, x[6])>(); // { dg-error "type/value mismatch|offsetof\\(T, x\\\[6\\\]\\)|expected" }
};
template<typename T> struct D
{
- D<__builtin_offsetof(T, x.y[6].z)>(); // { dg-error "type/value mismatch|offsetof\\(T, x.y\\\[6\\\].z\\)" }
+ D<__builtin_offsetof(T, x.y[6].z)>(); // { dg-error "type/value mismatch|offsetof\\(T, x.y\\\[6\\\].z\\)|expected" }
};
struct E { int x; };
template<typename T> struct F
{
- F<__builtin_offsetof(E, x)>(); // { dg-error "type/value mismatch|offsetof\\(E, x\\)" }
+ F<__builtin_offsetof(E, x)>(); // { dg-error "type/value mismatch|offsetof\\(E, x\\)|expected" }
};
diff --git a/gcc/testsuite/g++.old-deja/g++.other/inline15.C b/gcc/testsuite/g++.old-deja/g++.other/inline15.C
index 43f7f5e..a31c609 100644
--- a/gcc/testsuite/g++.old-deja/g++.other/inline15.C
+++ b/gcc/testsuite/g++.old-deja/g++.other/inline15.C
@@ -1,4 +1,4 @@
-// { dg-do assemble }
+// { dg-do assemble { target c++17_down } }
// { dg-options "-O1" }
// Origin: Jakub Jelinek <jakub@redhat.com>
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C b/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C
index a8be91d..bf418ba 100644
--- a/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C
+++ b/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C
@@ -4,7 +4,7 @@
template <class T>
struct A {
- A<T>();
+ A<T>(); // { dg-error "expected" "" { target c++20 } }
};
template <class T>