[PATCH] D152788: [Clang] Show type in enum out of range diagnostic
Dimitry Andric via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 13 11:36:05 PDT 2023
dim updated this revision to Diff 531011.
dim added a comment.
Add release note and test with template instantiation.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152788/new/
https://reviews.llvm.org/D152788
Files:
clang/docs/ReleaseNotes.rst
clang/test/SemaCXX/constant-expression-cxx11.cpp
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2476,6 +2476,16 @@
const NumberType neg_one = (NumberType) ((NumberType) 0 - (NumberType) 1); // ok, not a constant expression context
}
+template<class T, unsigned size> struct Bitfield {
+ static constexpr T max = static_cast<T>((1 << size) - 1);
+};
+
+void testValueInRangeOfEnumerationValuesViaTemplate() {
+ Bitfield<E2, 3> good;
+ Bitfield<E2, 4> bad;
+ // cxx11-error at -6 {{integer value 15 is outside the valid range of values [0, 7] for the enumeration type 'E2'}}
+}
+
enum SortOrder {
AscendingOrder,
DescendingOrder
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -340,6 +340,9 @@
can be controlled using ``-fcaret-diagnostics-max-lines=``.
- Clang no longer emits ``-Wunused-variable`` warnings for variables declared
with ``__attribute__((cleanup(...)))`` to match GCC's behavior.
+- When diagnosing a constant expression where an enum without a fixed underlying
+ type is set to a value outside the range of the enum's values, clang will now
+ print the name of the enum in question.
Bug Fixes in This Version
-------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152788.531011.patch
Type: text/x-patch
Size: 1437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230613/3211f0a6/attachment.bin>
More information about the cfe-commits
mailing list