<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 - -Wdouble-promotion false positive on C++11 brace initialization"
href="https://bugs.llvm.org/show_bug.cgi?id=34062">34062</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wdouble-promotion false positive on C++11 brace 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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>abigail.buccaneer@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Clang's -Wdouble-promotion flags all cases where a float is implicitly
converted to a double. The conversion is lossless but often unintentional and
can be a performance issue. When the conversion is intentional, the solution
is to explicitly cast with static_cast or a C-style cast. Unfortunately, a
C++11-style brace-init of double is flagged as an implicit conversion. This
should be considered an explicit conversion for the sake of -Wdouble-promotion
as some modern C++ guidelines recommend using brace-init for casting when the
cast cannot change the value.
$ cat test.cpp
double f() { return double{1.f}; }
$ clang++-6.0 -c -std=c++2a -Wdouble-promotion -Werror test.cpp
test.cpp:1:28: error: implicit conversion increases floating-point
precision: 'float' to 'double'
[-Werror,-Wdouble-promotion]
double f() { return double{1.f}; }
~^~~
1 error generated.
$ clang++-6.0 --version | head -n 1
clang version 6.0.0-svn309896-1~exp1 (trunk)</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>