[clang-tools-extra] [llvm] [clang] [clang-tidy] modernize-use-digit-separator issue #35414 (PR #76153)

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 21 05:25:35 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 513c2151cd0cddd90af91a6614b15b74b538963e 1db3de8b415a5526309c7167dec43d513a1d6570 -- clang-tools-extra/clang-tidy/modernize/UseDigitSeparatorCheck.cpp clang-tools-extra/clang-tidy/modernize/UseDigitSeparatorCheck.h clang-tools-extra/test/clang-tidy/checkers/modernize/use-digit-separator.cpp clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseDigitSeparatorCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDigitSeparatorCheck.cpp
index a5503f57ec..34c3cc1822 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDigitSeparatorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDigitSeparatorCheck.cpp
@@ -24,7 +24,8 @@ std::string
 getFormatedScientificFloatString(const llvm::StringRef OriginalLiteralString);
 
 std::vector<std::basic_string<char>>
-splitStringByGroupSize(const std::basic_string<char> &String, size_t GroupSize) {
+splitStringByGroupSize(const std::basic_string<char> &String,
+                       size_t GroupSize) {
   std::vector<std::basic_string<char>> Result;
   std::basic_string<char> ReversedString(String.rbegin(), String.rend());
 
@@ -33,12 +34,16 @@ splitStringByGroupSize(const std::basic_string<char> &String, size_t GroupSize)
   }
 
   std::reverse(Result.begin(), Result.end());
-  std::for_each(Result.begin(), Result.end(), [](std::basic_string<char> &Str) {return std::reverse(Str.begin(), Str.end());});
+  std::for_each(Result.begin(), Result.end(), [](std::basic_string<char> &Str) {
+    return std::reverse(Str.begin(), Str.end());
+  });
 
   return Result;
 }
 
-std::string getFormatedIntegerString(const llvm::StringRef OriginalLiteralString, const llvm::APInt IntegerValue) {
+std::string
+getFormatedIntegerString(const llvm::StringRef OriginalLiteralString,
+                         const llvm::APInt IntegerValue) {
   // Configure formatting
   unsigned int Radix;
   size_t GroupSize;
@@ -76,19 +81,20 @@ std::string getFormatedIntegerString(const llvm::StringRef OriginalLiteralString
       splitStringByGroupSize(toString(IntegerValue, Radix, true), GroupSize);
   const std::string FormatedLiteralString =
       Prefix +
-      std::accumulate(
-          SplittedIntegerLiteral.begin(), SplittedIntegerLiteral.end(),
-          std::string(""),
-          [](std::basic_string<char> S1, std::basic_string<char> S2) {
-            return S1 + "\'" + S2;
-          })
-          .erase(0, 1) + Postfix;
+      std::accumulate(SplittedIntegerLiteral.begin(),
+                      SplittedIntegerLiteral.end(), std::string(""),
+                      [](std::basic_string<char> S1,
+                         std::basic_string<char> S2) { return S1 + "\'" + S2; })
+          .erase(0, 1) +
+      Postfix;
 
   return FormatedLiteralString;
 }
 
-std::string getFormatedFloatString(const llvm::StringRef OriginalLiteralString, const llvm::APFloat FloatValue) {
-  if (OriginalLiteralString.contains('E') || OriginalLiteralString.contains('e')) {
+std::string getFormatedFloatString(const llvm::StringRef OriginalLiteralString,
+                                   const llvm::APFloat FloatValue) {
+  if (OriginalLiteralString.contains('E') ||
+      OriginalLiteralString.contains('e')) {
     return getFormatedScientificFloatString(OriginalLiteralString);
   }
 
@@ -177,8 +183,10 @@ void UseDigitSeparatorCheck::registerMatchers(MatchFinder *Finder) {
 void UseDigitSeparatorCheck::check(const MatchFinder::MatchResult &Result) {
   const ASTContext &Context = *Result.Context;
   const SourceManager &Source = Context.getSourceManager();
-  const IntegerLiteral *MatchedInteger = Result.Nodes.getNodeAs<IntegerLiteral>("integerLiteral");
-  const FloatingLiteral *MatchedFloat = Result.Nodes.getNodeAs<FloatingLiteral>("floatLiteral");
+  const IntegerLiteral *MatchedInteger =
+      Result.Nodes.getNodeAs<IntegerLiteral>("integerLiteral");
+  const FloatingLiteral *MatchedFloat =
+      Result.Nodes.getNodeAs<FloatingLiteral>("floatLiteral");
 
   if (MatchedInteger != nullptr) {
     // Get original literal source text
@@ -188,7 +196,8 @@ void UseDigitSeparatorCheck::check(const MatchFinder::MatchResult &Result) {
 
     // Get formatting literal text
     const llvm::APInt IntegerValue = MatchedInteger->getValue();
-    const std::string FormatedLiteralString = getFormatedIntegerString(OriginalLiteralString, IntegerValue);
+    const std::string FormatedLiteralString =
+        getFormatedIntegerString(OriginalLiteralString, IntegerValue);
 
     // Compare the original and formatted representation of a literal
     if (OriginalLiteralString != FormatedLiteralString) {
@@ -206,7 +215,8 @@ void UseDigitSeparatorCheck::check(const MatchFinder::MatchResult &Result) {
 
     // Get formatting literal text
     const llvm::APFloat FloatValue = MatchedFloat->getValue();
-    const std::string FormatedLiteralString = getFormatedFloatString(OriginalLiteralString, FloatValue);
+    const std::string FormatedLiteralString =
+        getFormatedFloatString(OriginalLiteralString, FloatValue);
 
     // Compare the original and formatted representation of a literal
     if (OriginalLiteralString != FormatedLiteralString) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/76153


More information about the cfe-commits mailing list