Commit 4a826ca6 by Jason Merrill Committed by Jason Merrill

Implement P0127R2, Declaring non-type parameters with auto.

gcc/cp/
	* cp-tree.h (enum auto_deduction_context): Add adc_unify.
	* decl.c (grokdeclarator): Allow 'auto' in C++17 template non-type
	parameter types.
	* pt.c (do_auto_deduction): Add outer_targs parameter.
	(convert_template_argument): Call do_auto_deduction.  If adc_unify,
	don't give up on dependent init.
	(unify): Likewise.  In C++17, walk into the type of a
	TEMPLATE_PARM_INDEX.
	(for_each_template_parm): Add any_fn parameter.
	(struct pair_fn_data): Likewise.
	(for_each_template_parm_r): Call it for any tree.  In C++17, walk
	into the type of a TEMPLATE_PARM_INDEX.
	(zero_r, array_deduction_r, try_array_deduction): New.
	(type_unification_real): Call try_array_deduction.
	(get_partial_spec_bindings): Likewise.
gcc/c-family/
	* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_template_auto.

From-SVN: r242017
parent ff1f317b
2016-11-09 Jason Merrill <jason@redhat.com>
* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_template_auto.
2016-11-09 Jakub Jelinek <jakub@redhat.com>
* c-ubsan.c (ubsan_instrument_shift): Handle split
......
......@@ -942,6 +942,7 @@ c_cpp_builtins (cpp_reader *pfile)
cpp_define (pfile, "__cpp_aggregate_bases=201603");
cpp_define (pfile, "__cpp_deduction_guides=201606");
cpp_define (pfile, "__cpp_noexcept_function_type=201510");
cpp_define (pfile, "__cpp_template_auto=201606");
}
if (flag_concepts)
cpp_define (pfile, "__cpp_concepts=201507");
......
2016-11-09 Jason Merrill <jason@redhat.com>
Implement P0127R2, Declaring non-type parameters with auto.
* cp-tree.h (enum auto_deduction_context): Add adc_unify.
* decl.c (grokdeclarator): Allow 'auto' in C++17 template non-type
parameter types.
* pt.c (do_auto_deduction): Add outer_targs parameter.
(convert_template_argument): Call do_auto_deduction. If adc_unify,
don't give up on dependent init.
(unify): Likewise. In C++17, walk into the type of a
TEMPLATE_PARM_INDEX.
(for_each_template_parm): Add any_fn parameter.
(struct pair_fn_data): Likewise.
(for_each_template_parm_r): Call it for any tree. In C++17, walk
into the type of a TEMPLATE_PARM_INDEX.
(zero_r, array_deduction_r, try_array_deduction): New.
(type_unification_real): Call try_array_deduction.
(get_partial_spec_bindings): Likewise.
2016-11-07 Jason Merrill <jason@redhat.com>
Implement P0012R1, Make exception specifications part of the type
......
......@@ -5163,6 +5163,7 @@ enum auto_deduction_context
adc_unspecified, /* Not given */
adc_variable_type, /* Variable initializer deduction */
adc_return_type, /* Return type deduction */
adc_unify, /* Template argument deduction */
adc_requirement /* Argument dedution constraint */
};
......@@ -6088,7 +6089,8 @@ extern tree make_template_placeholder (tree);
extern tree do_auto_deduction (tree, tree, tree);
extern tree do_auto_deduction (tree, tree, tree,
tsubst_flags_t,
auto_deduction_context);
auto_deduction_context,
tree = NULL_TREE);
extern tree type_uses_auto (tree);
extern tree type_uses_auto_or_concept (tree);
extern void append_type_to_template_for_access_check (tree, tree, tree,
......
......@@ -11135,7 +11135,8 @@ grokdeclarator (const cp_declarator *declarator,
if (ctype || in_namespace)
error ("cannot use %<::%> in parameter declaration");
if (type_uses_auto (type))
if (type_uses_auto (type)
&& !(cxx_dialect >= cxx1z && template_parm_flag))
{
if (cxx_dialect >= cxx14)
error ("%<auto%> parameter not permitted in this context");
......
......@@ -111,7 +111,7 @@ badthrow2 () throw (auto &) // { dg-error "invalid use of|expected" }
{
}
template <auto V = 4> struct G {}; // { dg-error "auto" }
template <auto V = 4> struct G {}; // { dg-error "auto" "" { target { ! c++1z } } }
template <typename T> struct H { H (); ~H (); };
H<auto> h; // { dg-error "invalid|initializer" }
......
......@@ -368,6 +368,12 @@
# error "__cpp_aligned_new != 201606"
#endif
#ifndef __cpp_template_auto
# error "__cpp_template_auto"
#elif __cpp_template_auto != 201606
# error "__cpp_template_auto != 201606"
#endif
#ifndef __cpp_inline_variables
# error "__cpp_inline_variables"
#elif __cpp_inline_variables != 201606
......
// Testcase from P0127R2
// { dg-options -std=c++1z }
template <long n> struct A { };
template <class T> struct C;
template <class T, T n> struct C<A<n>>
{
using Q = T;
};
typedef long R;
typedef C<A<2>>::Q R; // OK; T was deduced to long from the template argument value in the type A<2>
// Testcase from P0127R2
// { dg-options -std=c++1z }
template <typename T> struct S;
template <typename T, T n> struct S<int[n]> {
using Q = T;
};
typedef S<int[42]>::Q V;
typedef decltype(sizeof 0) V; // OK; T was deduced to std::size_t from the type int[42]
// Testcase from P0127R2
// { dg-options -std=c++1z }
template<auto n> struct B { decltype(n) f = n; };
B<5> b1; // OK: template parameter type is int
B<'a'> b2; // OK: template parameter type is char
B<2.5> b3; // { dg-error "" } template parameter type cannot be double
template <auto n> void f(B<n>) { }
int main()
{
f(B<42>());
f(B<'a'>());
}
// { dg-options -std=c++1z }
template <class T, T n> void f(T, int (&)[n]);
template <class T, T n> void g(int (&)[n], T);
template <class T, T n> void h(int (&)[n]);
int main()
{
const int i = 42;
int ar[i];
h(ar);
f(i, ar);
g(ar, i);
}
// { dg-options -std=c++1z }
template <class T> struct A
{
template <auto v> struct Y;
template <auto* p> struct Y<p> { using type1 = decltype (p); };
template <auto** pp> struct Y<pp> { using type2 = decltype (pp); };
};
int i;
int *p;
A<void>::Y<&i>::type1 t1;
A<void>::Y<&p>::type2 t2;
// { dg-do compile { target c++11 } }
template <int N> struct A;
template <typename T, T N> int foo(A<N> *) = delete;
void foo(void *);
void bar(A<0> *p) {
foo(p); // { dg-error "" "" { target c++1z } }
}
......@@ -14,7 +14,7 @@ template<typename T, typename T::foo V>
struct Y { };
template<typename T, typename U, U v>
struct Y<T, v> { }; // { dg-error "not deducible|U" }
struct Y<T, v> { }; // { dg-error "not deducible|U" "" { target { ! c++1z } } }
template<typename T, T V>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment