<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82167>82167</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang rejects valid program involving user defined literal
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ranaanoop
</td>
</tr>
</table>
<pre>
The following valid(afaik) program is rejected by clang but accepted by gcc and msvc.
```
#include <array>
template<std::size_t N>
struct Literal
{
std::array<char, N> arr;
constexpr Literal(char const(&pp)[N]): arr(""){}
};
template<Literal>
constexpr auto operator""_S()
{
return 4;
}
int main() {
auto i = "test"_S;
auto j = "ch"_S;
}
```
Clang says:
```
<source>:7:48: error: initializer-string for char array is too long, array size is 3 but initializer has size 5 (including the null terminating character)
7 | constexpr Literal(char const(&pp)[N]): arr(""){}
|
<source>:17:15: note: in instantiation of member function 'Literal<3>::Literal' requested here
17 | auto j = "ch"_S;
```
Another thing to note that if we write `auto i = "test"_S; auto j = "chjjgjgjt"_S;` then clang starts [accepting](https://godbolt.org/z/qGPjhYeKe).
Similarly clang also [accepts](https://godbolt.org/z/Kcz3rco33) `auto i = "test"_S; auto j = "chjt"_S;`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU2P2zYQ_TX0ZZCFRMq2dNDBa8c9pAgKpJeeApoaSXQpUiFHu9399QUpr2xvFkUOBQSZJmfem4-noQxBdxaxZutHtj6s5ES987WXVkrr3Lg6ueal_rNHaJ0x7lnbDp6k0Q3jpWyl_pvxCkbvOi8H0AE8nlERNnB6AWWk7eA0EUilcLzsdkqBtA0M4Uk9sOzAst3lvckuz_yXC22VmRoEJvbSe_nCxOdbB8JhNJKQiX2ghokdE7ugX_E7wdfFNJCfFMHvmtBLc3HfPs4LAIDF9UKxV730jO8TBkjvmbixVs4Gwn9GvyDyMjrMB4yXjG_GkfGKrR-_svUhrsQuwcQ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