pt.c (do_auto_deduction): In direct-init context, { x } deduces from x.

N3922
	* pt.c (do_auto_deduction): In direct-init context, { x } deduces
	from x.

From-SVN: r218685
This commit is contained in:
Jason Merrill 2014-12-12 12:52:28 -05:00 committed by Jason Merrill
parent e3501bab81
commit c0b6f54bd3
5 changed files with 37 additions and 2 deletions

View File

@ -1,5 +1,9 @@
2014-12-12 Jason Merrill <jason@redhat.com>
N3922
* pt.c (do_auto_deduction): In direct-init context, { x } deduces
from x.
* cp-tree.h (NAMESPACE_ABI_TAG): New.
* name-lookup.c (handle_namespace_attrs): Set it.
* class.c (check_tag): Split out from find_abi_tags_r.

View File

@ -5546,6 +5546,8 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p,
of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
a CONSTRUCTOR (with a record type). */
if (TREE_CODE (init) == CONSTRUCTOR
/* Don't complain about a capture-init. */
&& !CONSTRUCTOR_IS_DIRECT_INIT (init)
&& BRACE_ENCLOSED_INITIALIZER_P (init)) /* p7626.C */
{
if (SCALAR_TYPE_P (type))

View File

@ -22117,7 +22117,21 @@ do_auto_deduction (tree type, tree init, tree auto_node)
initializer is a braced-init-list (8.5.4), with
std::initializer_list<U>. */
if (BRACE_ENCLOSED_INITIALIZER_P (init))
type = listify_autos (type, auto_node);
{
if (!DIRECT_LIST_INIT_P (init))
type = listify_autos (type, auto_node);
else if (CONSTRUCTOR_NELTS (init) == 1)
init = CONSTRUCTOR_ELT (init, 0)->value;
else
{
if (permerror (input_location, "direct-list-initialization of "
"%<auto%> requires exactly one element"))
inform (input_location,
"for deduction to %<std::initializer_list%>, use copy-"
"list-initialization (i.e. add %<=%> before the %<{%>)");
type = listify_autos (type, auto_node);
}
}
init = resolve_nondeduced_context (init);

View File

@ -0,0 +1,15 @@
// N3922
// { dg-do compile { target c++11 } }
#include <initializer_list>
template <class T, class U> struct same_type;
template <class T> struct same_type<T,T> {};
auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
same_type<decltype(x1),std::initializer_list<int>> s1;
auto x4 = { 3 }; // decltype(x4) is std::initializer_list<int>
same_type<decltype(x4),std::initializer_list<int>> s4;
auto x5{ 3 }; // decltype(x5) is int
same_type<decltype(x5),int> s5;
auto x2 = { 1, 2.0 }; // { dg-error "initializer_list" } cannot deduce element type
auto x3{ 1, 2 }; // { dg-error "one element" } not a single element

View File

@ -6,5 +6,5 @@
int main()
{
if ([x(42)]{ return x; }() != 42) __builtin_abort();
if ([x{1,2}]{ return x.begin()[0]; }() != 1) __builtin_abort();
if ([x{24}]{ return x; }() != 24) __builtin_abort();
}