Commit 31bfc9b9 by Jason Merrill Committed by Jason Merrill

Implement P0522R0, matching of template template arguments.

gcc/c-family/
	* c.opt (-fnew-ttp-matching): New flag.
	* c-opts.c (c_common_post_options): Default on if -std=c++1z.
gcc/cp/
	* pt.c (coerce_template_template_parms): Allow a template argument
	that's less specialized than the parameter.
	(unify_bound_ttp_args): Adjust parm's args to apply to arg's
	template.
	(coerce_template_args_for_ttp): Split out from
	lookup_template_class_1.
	(coerce_ttp_args_for_tta, store_defaulted_ttp)
	(lookup_defaulted_ttp, add_defaults_to_ttp): New.
	(process_partial_specialization): Set DECL_CONTEXT of
	template template-parameters.
	(coerce_template_parms): Only inform when complain.
	(expand_template_argument_pack): Handle error_mark_node.
	(convert_template_argument, template_args_equal, unify): Handle
	any_targ_node.
	* cp-tree.h (enum cp_tree_index): Add CPTI_ANY_TARG.
	(any_targ_node): New.
	* decl.c (cxx_init_decl_processing): Set it.
	* name-lookup.c (consider_binding_level): Ignore names with embedded
	spaces.

From-SVN: r243871
parent 3c75aaa3
2016-12-21 Jason Merrill <jason@redhat.com>
* c.opt (-fnew-ttp-matching): New flag.
* c-opts.c (c_common_post_options): Default on if -std=c++1z.
2016-12-14 Martin Jambor <mjambor@suse.cz> 2016-12-14 Martin Jambor <mjambor@suse.cz>
* c-omp.c: Include omp-general.h instead of omp-low.h. * c-omp.c: Include omp-general.h instead of omp-low.h.
......
...@@ -920,6 +920,10 @@ c_common_post_options (const char **pfilename) ...@@ -920,6 +920,10 @@ c_common_post_options (const char **pfilename)
if (!global_options_set.x_flag_new_inheriting_ctors) if (!global_options_set.x_flag_new_inheriting_ctors)
flag_new_inheriting_ctors = abi_version_at_least (11); flag_new_inheriting_ctors = abi_version_at_least (11);
/* For GCC 7, only enable DR150 resolution by default if -std=c++1z. */
if (!global_options_set.x_flag_new_ttp)
flag_new_ttp = (cxx_dialect >= cxx1z);
if (cxx_dialect >= cxx11) if (cxx_dialect >= cxx11)
{ {
/* If we're allowing C++0x constructs, don't warn about C++98 /* If we're allowing C++0x constructs, don't warn about C++98
......
...@@ -1443,6 +1443,10 @@ C++ ObjC++ Joined Ignore Warn(switch %qs is no longer supported) ...@@ -1443,6 +1443,10 @@ C++ ObjC++ Joined Ignore Warn(switch %qs is no longer supported)
fnew-abi fnew-abi
C++ ObjC++ Ignore Warn(switch %qs is no longer supported) C++ ObjC++ Ignore Warn(switch %qs is no longer supported)
fnew-ttp-matching
C++ ObjC++ Var(flag_new_ttp)
Implement resolution of DR 150 for matching of template template arguments.
fnext-runtime fnext-runtime
ObjC ObjC++ LTO Report RejectNegative Var(flag_next_runtime) ObjC ObjC++ LTO Report RejectNegative Var(flag_next_runtime)
Generate code for NeXT (Apple Mac OS X) runtime environment. Generate code for NeXT (Apple Mac OS X) runtime environment.
......
2016-12-21 Jason Merrill <jason@redhat.com> 2016-12-21 Jason Merrill <jason@redhat.com>
Implement P0522R0, matching of template template arguments.
* pt.c (coerce_template_template_parms): Allow a template argument
that's less specialized than the parameter.
(unify_bound_ttp_args): Adjust parm's args to apply to arg's
template.
(coerce_template_args_for_ttp): Split out from
lookup_template_class_1.
(coerce_ttp_args_for_tta, store_defaulted_ttp)
(lookup_defaulted_ttp, add_defaults_to_ttp): New.
(process_partial_specialization): Set DECL_CONTEXT of
template template-parameters.
(coerce_template_parms): Only inform when complain.
(expand_template_argument_pack): Handle error_mark_node.
(convert_template_argument, template_args_equal, unify): Handle
any_targ_node.
* cp-tree.h (enum cp_tree_index): Add CPTI_ANY_TARG.
(any_targ_node): New.
* decl.c (cxx_init_decl_processing): Set it.
* name-lookup.c (consider_binding_level): Ignore names with embedded
spaces.
PR c++/42329 PR c++/42329
* pt.c (unify_bound_ttp_args): Split out from unify. * pt.c (unify_bound_ttp_args): Split out from unify.
(try_class_unification): Handle BOUND_TEMPLATE_TEMPLATE_PARM. (try_class_unification): Handle BOUND_TEMPLATE_TEMPLATE_PARM.
......
...@@ -1140,6 +1140,8 @@ enum cp_tree_index ...@@ -1140,6 +1140,8 @@ enum cp_tree_index
CPTI_ALIGN_TYPE, CPTI_ALIGN_TYPE,
CPTI_ANY_TARG,
CPTI_MAX CPTI_MAX
}; };
...@@ -1245,6 +1247,9 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; ...@@ -1245,6 +1247,9 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
#define keyed_classes cp_global_trees[CPTI_KEYED_CLASSES] #define keyed_classes cp_global_trees[CPTI_KEYED_CLASSES]
/* A node which matches any template argument. */
#define any_targ_node cp_global_trees[CPTI_ANY_TARG]
/* Node to indicate default access. This must be distinct from the /* Node to indicate default access. This must be distinct from the
access nodes in tree.h. */ access nodes in tree.h. */
......
...@@ -4161,6 +4161,9 @@ cxx_init_decl_processing (void) ...@@ -4161,6 +4161,9 @@ cxx_init_decl_processing (void)
global_type_node = make_node (LANG_TYPE); global_type_node = make_node (LANG_TYPE);
record_unknown_type (global_type_node, "global type"); record_unknown_type (global_type_node, "global type");
any_targ_node = make_node (LANG_TYPE);
record_unknown_type (any_targ_node, "any type");
/* Now, C++. */ /* Now, C++. */
current_lang_name = lang_name_cplusplus; current_lang_name = lang_name_cplusplus;
......
...@@ -4758,8 +4758,10 @@ consider_binding_level (tree name, best_match <tree, tree> &bm, ...@@ -4758,8 +4758,10 @@ consider_binding_level (tree name, best_match <tree, tree> &bm,
&& DECL_ANTICIPATED (d)) && DECL_ANTICIPATED (d))
continue; continue;
if (DECL_NAME (d)) if (tree name = DECL_NAME (d))
bm.consider (DECL_NAME (d)); /* Ignore internal names with spaces in them. */
if (!strchr (IDENTIFIER_POINTER (name), ' '))
bm.consider (DECL_NAME (d));
} }
} }
......
...@@ -201,6 +201,7 @@ in the following sections. ...@@ -201,6 +201,7 @@ in the following sections.
-fno-implicit-inline-templates @gol -fno-implicit-inline-templates @gol
-fno-implement-inlines -fms-extensions @gol -fno-implement-inlines -fms-extensions @gol
-fnew-inheriting-ctors @gol -fnew-inheriting-ctors @gol
-fnew-ttp-matching @gol
-fno-nonansi-builtins -fnothrow-opt -fno-operator-names @gol -fno-nonansi-builtins -fnothrow-opt -fno-operator-names @gol
-fno-optional-diags -fpermissive @gol -fno-optional-diags -fpermissive @gol
-fno-pretty-templates @gol -fno-pretty-templates @gol
...@@ -2455,6 +2456,14 @@ inheritance. This is part of C++17 but also considered to be a Defect ...@@ -2455,6 +2456,14 @@ inheritance. This is part of C++17 but also considered to be a Defect
Report against C++11 and C++14. This flag is enabled by default Report against C++11 and C++14. This flag is enabled by default
unless @option{-fabi-version=10} or lower is specified. unless @option{-fabi-version=10} or lower is specified.
@item -fnew-ttp-matching
@opindex fnew-ttp-matching
Enable the P0522 resolution to Core issue 150, template template
parameters and default arguments: this allows a template with default
template arguments as an argument for a template template parameter
with fewer template parameters. This flag is enabled by default for
@option{-std=c++1z}.
@item -fno-nonansi-builtins @item -fno-nonansi-builtins
@opindex fno-nonansi-builtins @opindex fno-nonansi-builtins
Disable built-in declarations of functions that are not mandated by Disable built-in declarations of functions that are not mandated by
......
// { dg-do compile { target c++11 } } // { dg-do compile { target c++11 } }
// { dg-options -fno-new-ttp-matching }
template<class T> class A { /* ... */ }; template<class T> class A { /* ... */ };
template<class T, class U = T> class B { /* ... */ }; template<class T, class U = T> class B { /* ... */ };
template<class... Types> class C { /* ... */ }; template<class... Types> class C { /* ... */ };
......
// CWG 150: Matching of template template-arguments excludes compatible
// templates
// { dg-options -fnew-ttp-matching }
template<class T> class A { /* ... */ };
template<class T, class U = T> class B { /* ... */ };
template<template<class> class P> class X { /* ... */ };
X<A> xa; // OK
X<B> xb; // OK since P0522R0
#if __cpp_variadic_templates
template <class ... Types> class C { /* ... */ };
template<template<class ...> class Q> class Y { /* ... */ };
X<C> xc; // OK since P0522R0
Y<A> ya; // OK
Y<B> yb; // OK
Y<C> yc; // OK
#endif
#if __cpp_template_auto
template<auto n> class D { /* ... */ };
template<template<int> class R> class Z { /* ... */ };
Z<D> zd; // OK
#endif
// { dg-do compile { target c++11 } }
template<typename _Tp>
struct get_first_arg;
template<template<typename, typename...> class _Template, typename _Tp,
typename... _Types>
struct get_first_arg<_Template<_Tp, _Types...>>
{ using type = _Tp; };
template<typename T> struct A { };
template<class,class> struct same;
template<class T> struct same<T,T> {};
same<get_first_arg<A<int>>::type,
int> x;
// { dg-do compile { target c++11 } }
template <typename, typename> struct A { };
template <typename T> struct B { };
template <typename T, template <T...> class C, T... Is>
struct A<B<T>, C<Is...>>
{
using type = C<Is...>;
};
// PR c++/33213 // PR c++/33213
// { dg-do compile { target c++11 } } // { dg-do compile { target c++11 } }
// { dg-options -fno-new-ttp-matching }
template<template<typename> class...> struct A; template<template<typename> class...> struct A;
......
// PR c++/33213
// { dg-do compile { target c++11 } }
// { dg-options -fnew-ttp-matching }
template<template<typename> class...> struct A;
template<template<typename...> class... B> struct A<B...> {};
// PR c++/32565 // PR c++/32565
// { dg-do compile { target c++11 } } // { dg-do compile { target c++11 } }
// { dg-options -fno-new-ttp-matching }
template<typename...> struct A1; template<typename...> struct A1;
template<template<int, int...> class T> struct A1<T<0, 1> > {}; template<template<int, int...> class T> struct A1<T<0, 1> > {};
......
// PR c++/32565
// { dg-do compile { target c++11 } }
// { dg-options -fnew-ttp-matching }
template<typename...> struct A1;
template<template<int, int...> class T> struct A1<T<0, 1> > {};
template<int, int, int...> struct B1 {};
A1<B1<0, 1> > a1;
template<int...> struct B2 {};
A1<B2<0, 1> > a2;
// CWG 150: Matching of template template-arguments excludes compatible
// templates
// { dg-options -fnew-ttp-matching }
template<class T, class U = T> class B { /* ... */ };
#if __cpp_variadic_templates
template <class ... Types> class C { /* ... */ };
#endif
template<template<class> class P, class T> void f(P<T>);
int main()
{
f(B<int>());
f(B<int,float>()); // { dg-error "no match" }
#if __cpp_variadic_templates
f(C<int>());
#endif
}
// { dg-options -fno-new-ttp-matching }
template <template <typename> class C> template <template <typename> class C>
void f() {} void f() {}
......
// { dg-options -fnew-ttp-matching }
template <template <typename> class C>
void f() {}
template <typename T, typename U = int>
struct S {};
template void f<S>();
// { dg-options -fno-new-ttp-matching }
template <template <typename> class C> template <template <typename> class C>
void f(C<double>) {} void f(C<double>) {}
......
// { dg-options -fnew-ttp-matching }
template <template <typename> class C>
void f(C<double>) {}
template <typename T, typename U = int>
struct S {};
template void f(S<double>);
// { dg-options -fno-new-ttp-matching }
// { dg-do compile } // { dg-do compile }
namespace mpl { namespace mpl {
template <typename, typename = int> struct lambda; template <typename, typename = int> struct lambda;
......
// { dg-do assemble } // { dg-options -fno-new-ttp-matching }
template <int i> class C {}; template <int i> class C {};
template <template <long> class TT> class D {}; template <template <long> class TT> class D {};
......
// { dg-options -fnew-ttp-matching }
template <int i> class C {};
template <template <long> class TT> class D {};
int main()
{
D<C> d;
}
2016-12-16 Jason Merrill <jason@redhat.com> 2016-12-21 Jason Merrill <jason@redhat.com>
* testsuite/util/testsuite_tr1.h (test_property): Don't define both * testsuite/util/testsuite_tr1.h (test_property): Don't define both
variadic and non-variadic overloads. variadic and non-variadic overloads.
......
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