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

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 01:49:20 PDT 2022


tbaeder updated this revision to Diff 449589.
tbaeder added a comment.

I just took the plunge and made `DiagnoseStaticAssertDetails()` take into account all static assertions, regardless of integer literals. It now also prints integers, booleans, chars and floats correctly.

For example:

  test.cpp:30:1: error: static assertion failed due to requirement 'inv(true) == inv(false)'
  static_assert(inv(true) == inv(false));
  ^             ~~~~~~~~~~~~~~~~~~~~~~~
  test.cpp:30:15: note: left-hand side of operator '==' evaluates to 'false'
  static_assert(inv(true) == inv(false));
                ^~~~~~~~~
  test.cpp:30:28: note: right-hand side of operator '==' evaluates to 'true'
  static_assert(inv(true) == inv(false));
                             ^~~~~~~~~~

the output when both sides are printed is rather clumsy to me, and some things are not handled at all (e.g. failed static assertions when the toplevel expression is not a `BinaryOpertator`, e.g. `static_assert(!k)` - the user doesn't know what value `k` is, which is important in case `k` is of an integer type).

But again, this kind of begs people to suggest more and more improvements, but I think this is a good enough start :)


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

https://reviews.llvm.org/D130894

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p3.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
  clang/test/Lexer/cxx1z-trigraphs.cpp
  clang/test/PCH/cxx-templates.cpp
  clang/test/Parser/objc-static-assert.mm
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/static-assert-cxx17.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130894.449589.patch
Type: text/x-patch
Size: 20237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220803/b0dc602a/attachment-0001.bin>


More information about the cfe-commits mailing list