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?
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?
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits