c++: Aggregate CTAD and string constants.

In CWG discussion, it was suggested that deduction from a string literal
should be to reference-to-const, so that we deduce 'char' rather than 'const
char' for T.

gcc/cp/ChangeLog:

	* pt.c (collect_ctor_idx_types): Add 'const' when deducing from
	a string constant.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/class-deduction-aggr7.C: New test.
This commit is contained in:
Jason Merrill 2020-07-08 01:11:44 -04:00
parent 87891d5eaf
commit d0ffe9d5dc
2 changed files with 21 additions and 2 deletions

View File

@ -28357,8 +28357,13 @@ collect_ctor_idx_types (tree ctor, tree list, tree elt = NULL_TREE)
if (TREE_CODE (ftype) == ARRAY_TYPE
&& (BRACE_ENCLOSED_INITIALIZER_P (val)
|| TREE_CODE (val) == STRING_CST))
ftype = (cp_build_reference_type
(ftype, BRACE_ENCLOSED_INITIALIZER_P (val)));
{
if (TREE_CODE (val) == STRING_CST)
ftype = cp_build_qualified_type
(ftype, cp_type_quals (ftype) | TYPE_QUAL_CONST);
ftype = (cp_build_reference_type
(ftype, BRACE_ENCLOSED_INITIALIZER_P (val)));
}
list = tree_cons (arg, ftype, list);
}

View File

@ -0,0 +1,14 @@
// { dg-do compile { target c++20 } }
template <class T, int N>
struct A
{
T ar[N];
};
A a = { "foo" };
template<class, class> struct same;
template<class T> struct same<T,T> {};
same<decltype (a.ar), char[4]> s;