<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Clang does not detect narrowing in aggregate (array) initialization"
href="https://bugs.llvm.org/show_bug.cgi?id=49676">49676</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang does not detect narrowing in aggregate (array) initialization
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dangelog@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Testcase:
extern long double l;
struct S {
S(int) {}
};
S s[] = { l };
This is supposed to be ill-formed because of narrowing. Clang does not reject
the code, nor it warns (as it usually does for narrowing).
The relevant rule is in [dcl.init.aggr]:
<a href="https://eel.is/c++draft/dcl.init.aggr#4.2.sentence-2">https://eel.is/c++draft/dcl.init.aggr#4.2.sentence-2</a>
<span class="quote">> Otherwise, the element is copy-initialized from the corresponding initializer-clause or is initialized with the brace-or-equal-initializer of the corresponding designated-initializer-clause.
> If that initializer is of the form assignment-expression or = assignment-expression and a narrowing conversion ([dcl.init.list]) is required to convert the expression, the program is ill-formed.</span >
That rule has been changed in C++20 with designated initializers, but the same
one was also there for C++17 and before, e.g.
<a href="https://timsong-cpp.github.io/cppwp/n4659/dcl.init.aggr#3">https://timsong-cpp.github.io/cppwp/n4659/dcl.init.aggr#3</a>
For comparison, GCC accepts with no warnings, but MSVC warns about narrowing.
For reference, I've reported this very same bug against GCC here
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99625">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99625</a> .</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>