[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
Mon Sep 27 06:40:20 PDT 2021
carlosgalvezp updated this revision to Diff 375242.
carlosgalvezp added a comment.
Fixed review comments
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110493/new/
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,29 @@
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;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:22: warning: integer literal has suffix 'ity', which is not uppercase
+
+template <int foo1u>
+struct Foo {
+ static constexpr int kFoo = foo1u;
+};
+
+template <int foo1u>
+constexpr int Foo<foo1u>::kFoo;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:19: warning: integer literal has suffix 'u', which is not uppercase
+
+// The template needs to be instantiated for diagnostics to show up
+void test_non_type_template_parameter() {
+ int x = Vector<10>::kCapacity;
+ int f = Foo<10>::kFoo;
+}
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, instead of
+ // something else, like a non-type template parameter.
+ 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.375242.patch
Type: text/x-patch
Size: 2017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210927/96895cac/attachment.bin>
More information about the cfe-commits
mailing list