From: Jason Merrill Date: Wed, 8 Jul 2020 05:11:44 +0000 (-0400) Subject: c++: Aggregate CTAD and string constants. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d0ffe9d5dc83092e6de996483c4c08b439a316c0;p=gcc.git 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. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index defc2a9abd8..5f43e9c5c69 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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); } diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr7.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr7.C new file mode 100644 index 00000000000..3505a8c97db --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr7.C @@ -0,0 +1,14 @@ +// { dg-do compile { target c++20 } } + +template +struct A +{ + T ar[N]; +}; + +A a = { "foo" }; + +template struct same; +template struct same {}; +same s; +