aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-11-06 15:20:00 -0500
committerJason Merrill <jason@gcc.gnu.org>2019-11-06 15:20:00 -0500
commitbabd71c168ad447d2d11886683dea263ba1d814d (patch)
tree890e5bf75cb35d71ba7b7d79a17c57c0156edc10 /gcc/cp
parent5d24b4f2dad8883db004481ebd633a0bf8d4f8e9 (diff)
downloadgcc-babd71c168ad447d2d11886683dea263ba1d814d.zip
gcc-babd71c168ad447d2d11886683dea263ba1d814d.tar.gz
gcc-babd71c168ad447d2d11886683dea263ba1d814d.tar.bz2
C++20 NB CA378 - Remove constrained non-template functions.
No real use cases have ever arisen for constraints on non-templated functions, and handling of them has never been entirely clear, so the committee agreed to accept this national body comment proposing that we remove them. * decl.c (grokfndecl): Reject constraints on non-templated function. From-SVN: r277891
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/decl.c12
2 files changed, 16 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e60a45b..c185af4 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2019-11-06 Jason Merrill <jason@redhat.com>
+
+ C++20 NB CA378 - Remove constrained non-template functions.
+ * decl.c (grokfndecl): Reject constraints on non-templated function.
+
2019-11-06 Matthias Kretz <m.kretz@gsi.de>
* parser.c (cp_parser_operator): Parse operator?: as an
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3bfcfb2..5c5a85e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9262,7 +9262,9 @@ grokfndecl (tree ctype,
if (flag_concepts)
{
tree tmpl_reqs = NULL_TREE;
- if (processing_template_decl > template_class_depth (ctype))
+ tree ctx = friendp ? current_class_type : ctype;
+ bool memtmpl = (processing_template_decl > template_class_depth (ctx));
+ if (memtmpl)
tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
tree ci = build_constraints (tmpl_reqs, decl_reqs);
if (concept_p && ci)
@@ -9270,6 +9272,14 @@ grokfndecl (tree ctype,
error_at (location, "a function concept cannot be constrained");
ci = NULL_TREE;
}
+ /* C++20 CA378: Remove non-templated constrained functions. */
+ if (ci && !flag_concepts_ts
+ && (!processing_template_decl
+ || (friendp && !memtmpl && !funcdef_flag)))
+ {
+ error_at (location, "constraints on a non-templated function");
+ ci = NULL_TREE;
+ }
set_constraints (decl, ci);
}