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

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 1 05:19:30 PDT 2022


tbaeder created this revision.
tbaeder added a reviewer: aaron.ballman.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For

  c++
  static constexpr m = 10;
  static_assert(m == 11);

the output is before:

  ./test.cpp:2:1: error: static_assert failed due to requirement 'm == 11'
  static_assert(m == 11);
  ^             ~~~~~~~
  1 error generated.

and after:

  ./test.cpp:2:1: error: static assertion failed due to requirement 'm == 11'
  static_assert(m == 11);
  ^             ~~~~~~~
  ./test.cpp:2:15: note: left-hand side of operator '==' evaluates to '10'
  static_assert(m == 11);
                ^
  1 error generated.

The patch adds a new function `Sema::DiagnoseStaticAssertDetails()`, which currently only handles binary operators with an integer literal on one side and a non-integer literal on the other side. This is intentionally kept simple, but can be improved incrementally over time of course.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130894

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
  clang/test/PCH/cxx-templates.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130894.448995.patch
Type: text/x-patch
Size: 8142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220801/0611f527/attachment-0001.bin>


More information about the cfe-commits mailing list