aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2015-10-19 22:48:51 -0400
committerJason Merrill <jason@gcc.gnu.org>2015-10-19 22:48:51 -0400
commit2a9fb7125e0b0e73cc36ebbff607aa03d6e02ea4 (patch)
treece34d7922020e02b9e9d7346c70ded9a6f9f13c7 /gcc/cp
parentdcdbc004d531b43e0583f8ac18def1474d64dc05 (diff)
downloadgcc-2a9fb7125e0b0e73cc36ebbff607aa03d6e02ea4.zip
gcc-2a9fb7125e0b0e73cc36ebbff607aa03d6e02ea4.tar.gz
gcc-2a9fb7125e0b0e73cc36ebbff607aa03d6e02ea4.tar.bz2
Implement N4268, Do constant evaluation of all non-type template args.
gcc/c-family/ * c-cppbuiltin.c (c_cpp_builtins): Define __cpp_nontype_template_args. gcc/cp/ * parser.c (cp_parser_template_argument): For C++1z just parse a constant-expression. * pt.c (convert_nontype_argument): For C++1z always call maybe_constant_value. From-SVN: r229019
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c9
-rw-r--r--gcc/cp/pt.c11
3 files changed, 24 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6bc52c3..842426b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2015-10-19 Jason Merrill <jason@redhat.com>
+ Implement N4268, Do constant evaluation of all non-type template args.
+ * parser.c (cp_parser_template_argument): For C++1z just parse a
+ constant-expression.
+ * pt.c (convert_nontype_argument): For C++1z always call
+ maybe_constant_value.
+
* constexpr.c (cxx_eval_constant_expression): Expand PTRMEM_CST
only when necessary.
(cxx_eval_component_reference): Like here.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 435757d..f07a5e4 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -14977,8 +14977,12 @@ cp_parser_template_argument (cp_parser* parser)
warn_deprecated_use (argument, NULL_TREE);
return argument;
}
- /* It must be a non-type argument. There permitted cases are given
- in [temp.arg.nontype]:
+ /* It must be a non-type argument. In C++17 any constant-expression is
+ allowed. */
+ if (cxx_dialect > cxx14)
+ goto general_expr;
+
+ /* Otherwise, the permitted cases are given in [temp.arg.nontype]:
-- an integral constant-expression of integral or enumeration
type; or
@@ -15090,6 +15094,7 @@ cp_parser_template_argument (cp_parser* parser)
return error_mark_node;
}
+ general_expr:
/* If the argument wasn't successfully parsed as a type-id followed
by '>>', the argument can only be a constant expression now.
Otherwise, we try parsing the constant-expression tentatively,
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 14a5ddd..142245a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6233,6 +6233,17 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
CONSTRUCTOR. */;
else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type))
expr = maybe_constant_value (expr);
+ else if (cxx_dialect >= cxx1z)
+ {
+ if (TREE_CODE (type) != REFERENCE_TYPE)
+ expr = maybe_constant_value (expr);
+ else if (REFERENCE_REF_P (expr))
+ {
+ expr = TREE_OPERAND (expr, 0);
+ expr = maybe_constant_value (expr);
+ expr = convert_from_reference (expr);
+ }
+ }
else if (TYPE_PTR_OR_PTRMEM_P (type))
{
tree folded = maybe_constant_value (expr);