Skip to content

Commit 8623a6a

Browse files
burblebeetkoeppe
authored andcommitted
CWG2681 Deducing member array type from string literal
1 parent d470e41 commit 8623a6a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

source/overloading.tex

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,14 @@
12581258
\begin{itemize}
12591259
\item
12601260
if $e_i$ is of array type and
1261-
$x_i$ is a \grammarterm{braced-init-list} or \grammarterm{string-literal},
1261+
$x_i$ is a \grammarterm{braced-init-list},
12621262
$\tcode{T}_i$ is an rvalue reference to the declared type of $e_i$, and
12631263
\item
1264+
if $e_i$ is of array type and
1265+
$x_i$ is a \grammarterm{string-literal},
1266+
$\tcode{T}_i$ is an lvalue reference to
1267+
the const-qualified declared type of $e_i$, and
1268+
\item
12641269
otherwise, $\tcode{T}_i$ is the declared type of $e_i$,
12651270
\end{itemize}
12661271
except that additional parameter packs of the form $\tcode{P}_j \tcode{...}$
@@ -1330,6 +1335,23 @@
13301335
}
13311336

13321337
G g(true, 'a', 1); // OK, deduces \tcode{G<char, bool>}
1338+
1339+
template<class T, std::size_t N>
1340+
struct H {
1341+
T array[N];
1342+
};
1343+
template<class T, std::size_t N>
1344+
struct I {
1345+
volatile T array[N];
1346+
};
1347+
template<std::size_t N>
1348+
struct J {
1349+
unsigned char array[N];
1350+
};
1351+
1352+
H h = { "abc" }; // OK, deduces \tcode{H<char, 4>} (not \tcode{T = const char})
1353+
I i = { "def" }; // OK, deduces \tcode{I<char, 4>}
1354+
J j = { "ghi" }; // error: cannot bind reference to array of \tcode{unsigned char} to array of \tcode{char} in deduction
13331355
\end{codeblock}
13341356
\end{example}
13351357

0 commit comments

Comments
 (0)