[PATCH] D130058: [Clang] Diagnose ill-formed constant expression when setting a non fixed enum to a value outside the range of the enumeration values
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 28 11:27:59 PDT 2022
shafik added inline comments.
================
Comment at: clang/test/Analysis/cfg.cpp:227
+enum MyEnum : int { A, B, C };
static const enum MyEnum D = (enum MyEnum) 32;
----------------
This is undefined behavior unless the enum has a fixed type, using `: int` above does that.
================
Comment at: clang/test/SemaCXX/enum-scoped.cpp:330
namespace PR35586 {
- enum C { R, G, B };
+ enum C { R=-1, G, B };
enum B { F = (enum C) -1, T}; // this should compile cleanly, it used to assert.
----------------
@erichkeane not sure if this fix for the test maintains the original intent of the test or not.
================
Comment at: cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp:28
void ttp_user() { }
-enum Enumeration { Enumerator1, Enumerator2, Enumerator3 = 1 };
+enum Enumeration : int { Enumerator1, Enumerator2, Enumerator3 = 1 };
enum class EnumerationClass { Enumerator1, Enumerator2, Enumerator3 = 1 };
----------------
These enums are used with undefined behavior later on by casting values outside of the range and using them as template arguments. Given them a fixed underling type removes the UB.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130058/new/
https://reviews.llvm.org/D130058
More information about the cfe-commits
mailing list