[PATCH] D130894: [clang] Print more information about failed static assertions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 4 04:41:50 PDT 2022


tbaeder added a comment.

IMO it's clear enough...

  test.cpp:24:1: error: static assertion failed due to requirement 'c != c'
  static_assert(c != c);
  ^             ~~~~~~
  test.cpp:24:17: note: expression evaluates to 'a != a'
  static_assert(c != c);
                ~~^~~~
  test.cpp:25:1: error: static assertion failed due to requirement 'c < 'a''
  static_assert(c < 'a');
  ^             ~~~~~~~
  test.cpp:25:15: note: left-hand side of operator '<' evaluates to 'a'
  static_assert(c < 'a');
                ^
  2 errors generated.

Printing the first note as ''a' != 'a'' doesn't make it clearer. But for

  test.cpp:24:1: error: static assertion failed due to requirement 'c != c'
  static_assert(c != c);
  ^             ~~~~~~
  test.cpp:24:17: note: expression evaluates to '0 != 0'
  static_assert(c != c);
                ~~^~~~
  test.cpp:25:1: error: static assertion failed due to requirement 'c > 'a''
  static_assert(c > 'a');
  ^             ~~~~~~~
  test.cpp:25:15: note: left-hand side of operator '>' evaluates to '0'
  static_assert(c > 'a');
                ^

where `c` is a char variable, the output looks kind of weird. "0 != 0" looks like we're comparing two integers.

We might also go the g++ route and use `evaluates to ('0' != '0')` for the full expression, but that looks weird for just one side: `evaluates to (6)`. But we could also always print the full expression so we only have one case.


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

https://reviews.llvm.org/D130894



More information about the cfe-commits mailing list