<html>
<head>
<base href="https://llvm.org/bugs/" />
</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-cl error with -Wc++11-narrowing and enums on code that MSVC accepts"
href="https://llvm.org/bugs/show_bug.cgi?id=30776">30776</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-cl error with -Wc++11-narrowing and enums on code that MSVC accepts
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>froydnj@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Compiling:
typedef enum {
MD_EXCEPTION_CODE_WIN_FLOAT_INEXACT_RESULT = 0xc000008f,
} MDExceptionCodeWin;
extern void g();
extern void h();
void
f(unsigned int code)
{
switch (code) {
case MD_EXCEPTION_CODE_WIN_FLOAT_INEXACT_RESULT:
g();
break;
default:
h();
break;
}
}
gives:
$ clang-cl -c enum-switch.cpp
enum-switch.cpp(2,3): warning: enumerator value is not representable in the
underlying type 'int' [-Wmicrosoft-enum-value]
MD_EXCEPTION_CODE_WIN_FLOAT_INEXACT_RESULT = 0xc000008f,
^
enum-switch.cpp(12,8): error: case value evaluates to -1073741681, which
cannot
be narrowed to type 'unsigned int' [-Wc++11-narrowing]
case MD_EXCEPTION_CODE_WIN_FLOAT_INEXACT_RESULT:
^
1 warning and 1 error generated.
whereas MSVC accepts the code without complaint.
I am reasonably sure this used to work, and not error, but I have not bisected
this, and may have a faulty memory in any event.
I realize that this is similar to <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED WONTFIX - clang-cl rejects code that Visual C++ accepts"
href="show_bug.cgi?id=25644">bug 25644</a>, and arguably the code should be
fixed (perhaps by explicitly making the enum have an underlying type of
uint32_t), but that is less straightforward in this case. The enum in question
may be in a header file that is shared between C/C++, and people may have,
shall we say, strong opinions about adding C++ goo. It's also not clear to me
whether mixing and matching different enum definitions like that would do the
right thing when calling between C and C++ functions.
Thoughts?</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>