[PATCH] D110493: [clang-tidy] Fix bug 51790 in readability-uppercase-literal-suffix

Carlos Galvez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 26 02:55:44 PDT 2021


carlosgalvezp created this revision.
carlosgalvezp added reviewers: llvm-commits, cfe-commits, steveire, lebedev.ri, alexfh, alexfh_.
carlosgalvezp added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.
carlosgalvezp requested review of this revision.

A bisect determined that the bug was introduced here:
https://github.com/llvm/llvm-project/commit/ea2225a10be986d226e041d20d36dff17e78daed

Unfortunately that patch can no longer be reverted on top of the main branch, so add a fix instead. Add a unit test to avoid regression in the future.

      

Fixes https://bugs.llvm.org/show_bug.cgi?id=51790


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110493

Files:
  clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp
@@ -270,3 +270,17 @@
 void d();
 void d() { c<b>(); }
 } // namespace
+
+// Check that non-type template parameters do not cause any diags.
+// https://bugs.llvm.org/show_bug.cgi?id=51790
+template <int capacity>
+struct Vector {
+  static constexpr int kCapacity = capacity;
+};
+
+template <int capacity>
+constexpr int Vector<capacity>::kCapacity;
+
+void test_vector() {
+  int x = Vector<10>::kCapacity;
+}
Index: clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -134,6 +134,11 @@
       CharSourceRange::getTokenRange(*Range), SM, LO, &Invalid);
   assert(!Invalid && "Failed to retrieve the source text.");
 
+  // Make sure the first character is actually a digit
+  // https://bugs.llvm.org/show_bug.cgi?id=51790
+  if (!std::isdigit(static_cast<unsigned char>(LiteralSourceText.front())))
+    return llvm::None;
+
   size_t Skip = 0;
 
   // Do we need to ignore something before actually looking for the suffix?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110493.375088.patch
Type: text/x-patch
Size: 1532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210926/ee3b17e2/attachment-0001.bin>


More information about the cfe-commits mailing list