From bff9327eb2aac72f78cbf49a2cc76843b57ae9af Mon Sep 17 00:00:00 2001 From: Kim Grasman Date: Sat, 1 Aug 2020 14:08:13 +0200 Subject: [PATCH] Use std::to_string instead of snprintf --- iwyu.cc | 9 +-------- more_tests/iwyu_include_picker_test.cc | 13 +++---------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/iwyu.cc b/iwyu.cc index 99046b2..8f93427 100644 --- a/iwyu.cc +++ b/iwyu.cc @@ -89,7 +89,6 @@ #include // for swap, find, make_pair #include // for size_t -#include // for snprintf #include // for atoi, exit #include #include // for swap @@ -232,12 +231,6 @@ using std::vector; namespace { -string IntToString(int i) { - char buf[64]; // big enough for any number - snprintf(buf, sizeof(buf), "%d", i); - return buf; -} - bool CanIgnoreLocation(SourceLocation loc) { // If we're in a macro expansion, we always want to treat this as // being in the expansion location, never the as-written location, @@ -451,7 +444,7 @@ class BaseAstVisitor : public RecursiveASTVisitor { // etc. string AnnotatedName(const string& name) const { return (PrintableCurrentLoc() + ": (" + - IntToString(current_ast_node_->depth()) + GetSymbolAnnotation() + + std::to_string(current_ast_node_->depth()) + GetSymbolAnnotation() + (current_ast_node_->in_forward_declare_context() ? ", fwd decl" : "") + ") [ " + name + " ] "); diff --git a/more_tests/iwyu_include_picker_test.cc b/more_tests/iwyu_include_picker_test.cc index be55316..8f2b72b 100644 --- a/more_tests/iwyu_include_picker_test.cc +++ b/more_tests/iwyu_include_picker_test.cc @@ -13,7 +13,6 @@ #include "iwyu_include_picker.h" #include -#include #include #include #include @@ -36,27 +35,21 @@ namespace include_what_you_use { namespace { -string IntToString(int i) { - char buf[64]; // big enough for any number - snprintf(buf, sizeof(buf), "%d", i); - return buf; -} - // Returns a string representing the first element where actual (a vector), // and expected (an array) differ, or "" if they're identical. template string VectorDiff(const string (&expected)[kCount], const vector& actual) { for (int i = 0; i < std::min(kCount, actual.size()); ++i) { if (expected[i] != actual[i]) { - return ("Differ at #" + IntToString(i) + ": expected=" + expected[i] + + return ("Differ at #" + std::to_string(i) + ": expected=" + expected[i] + ", actual=" + actual[i]); } } if (kCount < actual.size()) { - return ("Differ at #" + IntToString(kCount) + + return ("Differ at #" + std::to_string(kCount) + ": expected at EOF, actual=" + actual[kCount]); } else if (actual.size() < kCount) { - return ("Differ at #" + IntToString(kCount) + ": expected=" + + return ("Differ at #" + std::to_string(kCount) + ": expected=" + expected[actual.size()] + ", actual at EOF"); } else { return "";