= parser->greater_than_is_operator_p;
parser->greater_than_is_operator_p = true;
+ /* Don't synthesize an implicit template type parameter here. This
+ could happen with C++23 code like
+
+ void f(decltype(new auto{0}));
+
+ where we want to deduce the auto right away so that the parameter
+ is of type 'int *'. */
+ auto cleanup = make_temp_override
+ (parser->auto_is_implicit_function_template_parm_p, false);
+
/* Do not actually evaluate the expression. */
++cp_unevaluated_operand;
/* OK */;
else
{
- location_t loc = type_specifier_seq.locations[ds_type_spec];
- if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
+ if (!cp_parser_simulate_error (parser))
{
- if (!cp_parser_simulate_error (parser))
+ location_t loc = type_specifier_seq.locations[ds_type_spec];
+ if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
{
error_at (loc, "missing template arguments after %qT",
auto_node);
inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here",
tmpl);
}
+ else if (parser->in_template_argument_list_p)
+ error_at (loc, "%qT not permitted in template argument",
+ auto_node);
+ else
+ error_at (loc, "invalid use of %qT", auto_node);
}
- else if (parser->in_template_argument_list_p)
- error_at (loc, "%qT not permitted in template argument",
- auto_node);
- else
- error_at (loc, "invalid use of %qT", auto_node);
return error_mark_node;
}
}
&decl_specifiers,
&declares_class_or_enum);
+ /* [dcl.spec.auto.general]: "A placeholder-type-specifier of the form
+ type-constraint opt auto can be used as a decl-specifier of the
+ decl-specifier-seq of a parameter-declaration of a function declaration
+ or lambda-expression..." but we must not synthesize an implicit template
+ type parameter in its declarator. That is, in "void f(auto[auto{10}]);"
+ we want to synthesize only the first auto. */
+ auto cleanup = make_temp_override
+ (parser->auto_is_implicit_function_template_parm_p, false);
+
/* Complain about missing 'typename' or other invalid type names. */
if (!decl_specifiers.any_type_specifiers_p
&& cp_parser_parse_and_diagnose_invalid_type_name (parser))
= parser->non_integral_constant_expression_p;
parser->integral_constant_expression_p = false;
+ auto cleanup = make_temp_override
+ (parser->auto_is_implicit_function_template_parm_p, false);
+
/* Do not actually evaluate the expression. */
++cp_unevaluated_operand;
++c_inhibit_evaluation_warnings;
// { dg-do compile { target c++14 } }
auto l4 = [](auto v, auto (&array (int)) [5]) -> int { return v + array[0]; };
-auto l5 = [](auto v, auto (&array (auto)) [5]) -> int { return v + array[0]; };
+auto l5 = [](auto v, auto (&array (auto)) [5]) -> int { return v + array[0]; }; // { dg-error ".auto. parameter not permitted in this context" }
auto l6 = [](auto v, auto (&array (int int)) [5]) -> int { return v + array[0]; }; // { dg-error "two or more data types" }
auto l7 = [](auto v, auto (&array (int auto)) [5]) -> int { return v + array[0]; }; // { dg-error "two or more data types" }
void bar()
{
- fooA((auto*)0); // { dg-error "invalid use" }
- fooB((auto*)0); // { dg-error "invalid use" }
+ fooA((auto*)0); // { dg-error "expected" }
+ fooB((auto*)0); // { dg-error "expected" }
}
void foo();
-auto f = (auto(*)())(&foo); // { dg-error "invalid" }
+auto f = (auto(*)())(&foo); // { dg-error "expected" }
+// { dg-error "only available" "" { target c++20_down } .-1 }
--- /dev/null
+// PR c++/103401
+// { dg-do compile { target c++23 } }
+
+void f(decltype(auto(0))) { }
+
+int main()
+{
+ f<int,int>(0); // { dg-error "no matching function" }
+}
--- /dev/null
+// PR c++/103401
+// { dg-do compile { target c++23 } }
+
+void f1 (decltype(auto(0)));
+void f2 (decltype(auto{0}));
+void f3 (int = auto(42));
+void f4 (int = auto{42});
+void f5 (decltype(auto(0)) = auto(42));
+void f6 (auto (x));
+void f7 (int[auto(10)]);
+void f8 (int[auto{10}]);
+void f9 (auto[auto{10}]);
+void f10 (auto);
+void f11 (int x, decltype(x) y);
+void f12 (int[sizeof(auto{10})]);
+void f13 (int[sizeof(auto(10))]);
+void f14 (int[__extension__ alignof(auto{10})]);
+void f15 (int[__extension__ alignof(auto(10))]);
+
+void
+g ()
+{
+ int a[2];
+ f1 (1);
+ f2 (1);
+ f3 ();
+ f3 (1);
+ f4 ();
+ f4 (1);
+ f5 ();
+ f5 (1);
+ f6 ('a');
+ f7 (&a[0]);
+ f8 (&a[0]);
+ f9 (&a[0]);
+ f10 (1);
+ f11 (1, 2);
+ f12 (&a[0]);
+ f13 (&a[0]);
+ f14 (&a[0]);
+ f15 (&a[0]);
+}
--- /dev/null
+// PR c++/103401
+// { dg-do compile { target c++23 } }
+
+void f1(decltype(new auto{0}));
+void f2(decltype(new int{0}));
+
+void
+g ()
+{
+ int i;
+ void f3(decltype(new auto{0}));
+ void f4(decltype(new int{0}));
+ f1 (&i);
+ f2 (&i);
+ f3 (&i);
+ f4 (&i);
+}
template <typename T>
void foo1(T& t) {
typename T::template C<void> tcv = t;
- typename T::template C<auto> u = tcv; // { dg-error "not permitted" "" { target c++20 } }
- T::template C<auto>::f (tcv, u); // { dg-error "incomplete|not permitted" }
- (typename T::template D<auto> (t)); // { dg-error "invalid|not permitted|unable" }
+ typename T::template C<auto> u = tcv; // { dg-error "" "" { target c++20 } }
+ T::template C<auto>::f (tcv, u); // { dg-error "" }
+ (typename T::template D<auto> (t)); // { dg-error "" }
// { dg-warning "only available" "" { target c++17_down } .-1 }
}
template <typename T>
void foo2(T& t) {
typename T::template C<void> tcv = t;
- typename T::template C<auto> u = tcv; // { dg-error "not permitted" "" { target c++20 } }
- T::template C<auto>::f (tcv, u); // { dg-error "incomplete|not permitted" }
- T::template D<auto> (t); // { dg-error "invalid|not permitted" }
+ typename T::template C<auto> u = tcv; // { dg-error "" "" { target c++20 } }
+ T::template C<auto>::f (tcv, u); // { dg-error "" }
+ T::template D<auto> (t); // { dg-error "" }
}
struct T2 {
template <typename T>
void foo1(T& t) {
typename T::template C<void> tcv = t;
- typename T::template C<auto> u = tcv; // { dg-error "not permitted" "" { target c++20 } }
- T::template C<auto>::f (tcv, u); // { dg-error "incomplete|not permitted" }
- (typename T::template D<auto> (t)); // { dg-error "invalid|not permitted|no class" }
+ typename T::template C<auto> u = tcv; // { dg-error "" "" { target c++20 } }
+ T::template C<auto>::f (tcv, u); // { dg-error "" }
+ (typename T::template D<auto> (t)); // { dg-error "" }
// { dg-warning "only available" "" { target c++17_down } .-1 }
}
template <typename T>
void foo2(T& t) {
typename T::template C<void> tcv = t;
- typename T::template C<auto> u = tcv; // { dg-error "not permitted" "" { target c++20 } }
- T::template C<auto>::f (tcv, u); // { dg-error "incomplete|not permitted" }
- T::template D<auto> (t); // { dg-error "yields a type|not permitted" }
+ typename T::template C<auto> u = tcv; // { dg-error "" "" { target c++20 } }
+ T::template C<auto>::f (tcv, u); // { dg-error "" }
+ T::template D<auto> (t); // { dg-error "" }
}
struct T2 {
void bar()
{
- foo<auto>(); // { dg-error "not permitted|invalid|no matching function" }
+ foo<auto>(); // { dg-error "" }
}