/* Only plain decltype(auto) is allowed. */
if (tree a = type_uses_auto (type))
{
- if (AUTO_IS_DECLTYPE (a) && a != type)
+ if (AUTO_IS_DECLTYPE (a))
{
- error_at (typespec_loc, "%qT as type rather than "
- "plain %<decltype(auto)%>", type);
- return error_mark_node;
+ if (a != type)
+ {
+ error_at (typespec_loc, "%qT as type rather than "
+ "plain %<decltype(auto)%>", type);
+ return error_mark_node;
+ }
+ else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
+ {
+ error_at (typespec_loc, "%<decltype(auto)%> cannot be "
+ "cv-qualified");
+ return error_mark_node;
+ }
}
}
error ("%qT as type rather than plain %<decltype(auto)%>", type);
return error_mark_node;
}
+ else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
+ {
+ if (complain & tf_error)
+ error ("%<decltype(auto)%> cannot be cv-qualified");
+ return error_mark_node;
+ }
}
else
{
--- /dev/null
+// PR c++/79815
+// { dg-do compile { target c++14 } }
+
+decltype(auto) const x = 1; // { dg-error "cannot be cv-qualified" }
+volatile decltype(auto) x2 = 1; // { dg-error "cannot be cv-qualified" }
+const volatile decltype(auto) x3 = 1; // { dg-error "cannot be cv-qualified" }
+const decltype(auto) fn() { return 42; } // { dg-error "cannot be cv-qualified" }
+const decltype(auto) fn2(); // { dg-error "cannot be cv-qualified" }