[PATCH] D107294: [clang] adds warning to suggest users replace symbols with alt tokens

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 2 10:14:40 PDT 2021


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

C++'s alternative tokens are a good way to improve readability and
minimise bugs by expressing intention using words instead of symbols
(which can both be more easily misspelt _and_ misread).

This warning analyses the binary logical and bitwise operators and warns
if they aren't spelt using the alternative tokens. Bitwise compound
assignment and `!=` operators are not in scope since there's nothing to
misspel or misread.

Future work:

- add a fixit
- add a way for the compiler to detect when the pipe operator (`|`) is not being used for a bitwise-or operation
- possibly extend this warning beyond C++

Depends on D107291 <https://reviews.llvm.org/D107291>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107294

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseExpr.cpp
  clang/test/Parser/warn-use-alternative-tokens.c
  clang/test/Parser/warn-use-alternative-tokens.cpp
  clang/test/Sema/vector-gcc-compat.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107294.363513.patch
Type: text/x-patch
Size: 9206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210802/8a85b7c8/attachment.bin>


More information about the cfe-commits mailing list