<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 --- - -Wvarargs gives false positive with enum arguments"
href="https://llvm.org/bugs/show_bug.cgi?id=29140">29140</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wvarargs gives false positive with enum arguments
</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>All
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>friss@apple.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>The following code:
----------------------------
#include <stdarg.h>
enum E { A };
void foo(enum E e, ...) {
va_list arg;
va_start(arg, e);
}
----------------------------
Produces a warning since r267338:
/tmp/enum_varags.c:7:16: warning: passing an object that undergoes default
argument promotion to 'va_start' has undefined behavior [-Wvarargs]
va_start(arg, e);
^
/tmp/enum_varags.c:5:17: note: parameter of type 'enum E' is declared here
void foo(enum E e, ...) {
This is not UB because the enum is represented in a type compatible with int.
Excerpt from the mailing list conversation:
<span class="quote">>>>> Would you agree the warning as implemented gives false positives in that case?
>>> It depends entirely on the enumeration and what compatible type is
>>> chosen for it. If the compatible type is signed or unsigned int, then
>>> the warning would be a false-positive and we should silence it. If the
>>> compatible type is char, then the warning is not a false positive.
>> I think we agree? If I’m not mistaken, in clang’s case, an int compatible type will
>> always be chosen except if -fshort-enums is passed and the enum fits in a smaller
>> type. Do you want a PR?
> Yes, I think a PR is reasonable. There's also the packed attribute on
> an enum which acts the same as passing -fshort-enums, and there is the
> language extension for allowing enumerators larger than what fits into
> an int.</span ></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>