@@ -4127,7 +4127,7 @@ decl_constant_var_p (tree decl)
constant until its initializer is complete in case it's used in
its own initializer. */
maybe_instantiate_decl (decl);
- return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
+ return TREE_CONSTANT (decl);
}
/* Returns true if DECL could be a symbolic constant variable, depending on
@@ -4144,6 +4144,9 @@ decl_maybe_constant_var_p (tree decl)
if (DECL_HAS_VALUE_EXPR_P (decl))
/* A proxy isn't constant. */
return false;
+ if (TREE_CODE (type) == REFERENCE_TYPE)
+ /* References can be constant. */
+ return true;
return (CP_TYPE_CONST_NON_VOLATILE_P (type)
&& INTEGRAL_OR_ENUMERATION_TYPE_P (type));
}
@@ -1000,6 +1000,37 @@ dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags)
dump_type_suffix (pp, type, flags);
}
+/* Print an IDENTIFIER_NODE that is the name of a declaration. */
+
+static void
+dump_decl_name (cxx_pretty_printer *pp, tree t, int flags)
+{
+ /* These special cases are duplicated here so that other functions
+ can feed identifiers to error and get them demangled properly. */
+ if (IDENTIFIER_TYPENAME_P (t))
+ {
+ pp_cxx_ws_string (pp, "operator");
+ /* Not exactly IDENTIFIER_TYPE_VALUE. */
+ dump_type (pp, TREE_TYPE (t), flags);
+ return;
+ }
+ if (dguide_name_p (t))
+ {
+ dump_decl (pp, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t)),
+ TFF_PLAIN_IDENTIFIER);
+ return;
+ }
+
+ const char *str = IDENTIFIER_POINTER (t);
+ if (!strncmp (str, "_ZGR", 3))
+ {
+ pp_cxx_ws_string (pp, "<temporary>");
+ return;
+ }
+
+ pp_cxx_tree_identifier (pp, t);
+}
+
/* Dump a human readable string for the decl T under control of FLAGS. */
static void
@@ -1155,21 +1186,8 @@ dump_decl (cxx_pretty_printer *pp, tree t, int flags)
gcc_unreachable ();
break;
- /* These special cases are duplicated here so that other functions
- can feed identifiers to error and get them demangled properly. */
case IDENTIFIER_NODE:
- if (IDENTIFIER_TYPENAME_P (t))
- {
- pp_cxx_ws_string (pp, "operator");
- /* Not exactly IDENTIFIER_TYPE_VALUE. */
- dump_type (pp, TREE_TYPE (t), flags);
- break;
- }
- else if (dguide_name_p (t))
- dump_decl (pp, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t)),
- TFF_PLAIN_IDENTIFIER);
- else
- pp_cxx_tree_identifier (pp, t);
+ dump_decl_name (pp, t, flags);
break;
case OVERLOAD:
@@ -2078,10 +2078,9 @@ static tree
constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p)
{
while (TREE_CODE (decl) == CONST_DECL
- || (strict_p
- ? decl_constant_var_p (decl)
- : (VAR_P (decl)
- && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl)))))
+ || decl_constant_var_p (decl)
+ || (!strict_p && VAR_P (decl)
+ && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))))
{
tree init;
/* If DECL is a static data member in a template
@@ -30743,6 +30743,9 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind,
goto skip_comma;
decl = cp_parser_lookup_name_simple (parser, name, token->location);
+ if (VAR_P (decl))
+ /* Make decl_constant_var_p false for OpenMP variables. */
+ TREE_CONSTANT (decl) = false;
if (decl == error_mark_node)
cp_parser_name_lookup_error (parser, name, decl, NLE_NULL,
token->location);
new file mode 100644
@@ -0,0 +1,5 @@
+// { dg-do compile { target c++11 } }
+
+int &&r = 42;
+static_assert (r, ""); // { dg-error "temporary" }
+// { dg-prune-output "assert" }
new file mode 100644
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++11 } }
+
+int a[2] = { 1, 2 };
+
+int main()
+{
+ auto &r = a;
+ static_assert (&r[0] == &a[0], "");
+}