Open Quuxplusone opened 4 years ago
Attached ClangBugTest.zip
(248512 bytes, application/x-zip-compressed): Android Studio example project
Casting a literal to an enum type that doesn't have an enumeration value that matches is unspecified behavior in C, and explicitly UB in C++20.
src_flags is defined in android.c as:
iter_flags_t narrow, src_flags;
iter_flags_t is defined in android.h as:
typedef enum { ITER_NARROW = (1 << 0), ITER_LOCALIZED_ALPHA = (1 << 1), ITER_IGNORE_ALPHA = (1 << 2), ITER_IGNORE_RGB = (1 << 3) } iter_flags_t;
So the value 0
is not a valid iter_flags_t
.
general_composite_rect() has a conditional that may assign 0
to narrow
, which is then used to assign a value to src_flags
.
That looks fishy, but I haven't been able to come up with a smaller reproducer.
(In reply to Nick Desaulniers from comment #1)
> Casting a literal to an enum type that doesn't have an enumeration value
> that matches is unspecified behavior in C, and explicitly UB in C++20.
The C++ rule here is a bit looser than what you're describing: "the values of
the enumeration are the values representable by a hypothetical integer type
with minimal width M such that all enumerators can be represented". So it's
always okay to convert 0 to an enum type.
In any case, even if the code did have undefined behavior, that shouldn't lead
to a compile error.
ClangBugTest.zip
(248512 bytes, application/x-zip-compressed)