[PATCH] D147875: [clang][Diagnostics] WIP: Show line numbers when printing code snippets

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 9 01:28:03 PDT 2023


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

Just putting this here because it's a pretty simple patch as it turns out.

Caveats:

1. WIP, so I haven't fixed up or added any tests yet
2. We (probably) need a cmdline option to disable line numbers
3. With the default for `-fcaret-diagnostics-max-lines` being `1`, the line numbers don't make that much sense
4. caret, underline and fixits probably need a ` | ` prefix as well

Sample output:

  ./array.cpp:98:1: error: static assertion failed due to requirement 'func()'
    98 | static_assert(
         ^
    99 |     // I wonder if this works.
   100 |     // Also, what if it doesn't?
   101 |     func());
             ~~~~~~
  1 error generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147875

Files:
  clang/include/clang/Frontend/TextDiagnostic.h
  clang/lib/Frontend/TextDiagnostic.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147875.511963.patch
Type: text/x-patch
Size: 3290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230409/ffce5f66/attachment.bin>


More information about the cfe-commits mailing list