[PATCH] D152788: [Clang] Show type in enum out of range diagnostic

Dimitry Andric via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 14 11:08:44 PDT 2023


dim added inline comments.


================
Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:2479-2486
+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;
----------------
aaron.ballman wrote:
> Equivalent but a bit easier to tell where the diagnostic is expected to happen at.
> 
> Perhaps a good follow-up would be to find out why we're not printing an "instantiated from here" note for this case (CC @shafik), but no need to do that for this patch.
Ah, I didn't know that syntax. At first I had the `cxx11-error@` just below the `static_cast` in the `Bitfield` class, but it seemed clearer to do it the way I did.

That said, you are right that it would probably be handy to show where the instantiation is coming from (if there is a template involved), because currently it does not point you to the exact source line where the problem is: in this case the `bad` declaration.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152788/new/

https://reviews.llvm.org/D152788



More information about the cfe-commits mailing list