https://llvm.org/bugs/show_bug.cgi?id=29140

            Bug ID: 29140
           Summary: -Wvarargs gives false positive with enum arguments
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

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:

>>>> 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to