From 8e25d704e18ecf1b38cda61fa56b54262c6127e0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 09:30:24 +0000 Subject: [PATCH 1/2] Use const char* for literal-only string helpers Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/2992a9b8-3c9c-4541-ae03-8de3908d1b7c Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com> --- cpp2rust/converter/converter_lib.cpp | 2 +- cpp2rust/converter/converter_lib.h | 2 +- cpp2rust/converter/mapper.cpp | 6 +++--- cpp2rust/converter/models/converter_refcount.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 3f515788..325fa15a 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -380,7 +380,7 @@ clang::QualType GetReturnTypeOfFunction(const clang::CallExpr *expr) { return {}; } -std::string GetOverloadedOperator(const clang::FunctionDecl *decl) { +const char *GetOverloadedOperator(const clang::FunctionDecl *decl) { switch (decl->getOverloadedOperator()) { case clang::OO_Less: return "lt"; diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 3696d680..668e5150 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -91,7 +91,7 @@ template llvm::SmallString<16> GetNumAsString(const T &num) { clang::QualType GetReturnTypeOfFunction(const clang::CallExpr *expr); -std::string GetOverloadedOperator(const clang::FunctionDecl *decl); +const char *GetOverloadedOperator(const clang::FunctionDecl *decl); bool IsOverloadedComparisonOperator(const clang::CXXMethodDecl *decl); diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index a100c969..94a1861c 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -367,7 +367,7 @@ Map::const_iterator parallel_search(const Map &container, decltype(exprs_)::const_iterator search(const clang::Expr *expr) { auto qualified_name = ToString(expr); - auto result = parallel_search(exprs_, [&](std::string tpl) { + auto result = parallel_search(exprs_, [&](const std::string &tpl) { return matchTemplate(tpl, qualified_name); }); llvm::errs() << "search expr " << qualified_name << ", result:\n"; @@ -382,7 +382,7 @@ decltype(exprs_)::const_iterator search(const clang::Expr *expr) { decltype(types_)::const_iterator search(clang::QualType qual_type) { auto type = ToString(qual_type); auto result = parallel_search( - types_, [&](std::string tpl) { return matchTemplate(tpl, type); }); + types_, [&](const std::string &tpl) { return matchTemplate(tpl, type); }); llvm::errs() << "search type " << type << ", result: " << ((result == types_.end()) ? "None" : result->second.type_info.type) @@ -532,7 +532,7 @@ clang::QualType normalizeQualType(clang::QualType qual_type) { std::string mapTypeStringRecursive(const std::string &cpp_type) { auto rule = parallel_search( - types_, [&](std::string tpl) { return matchTemplate(tpl, cpp_type); }); + types_, [&](const std::string &tpl) { return matchTemplate(tpl, cpp_type); }); if (rule == types_.end()) { llvm::errs() << "cpp_type: " << cpp_type << '\n'; assert(0 && "Type is not present in types_"); diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 81025901..a3479480 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -196,7 +196,7 @@ class ConverterRefCount final : public Converter { FullRefCount, }; - std::string ConversionKindToString(ConversionKind k) { + const char *ConversionKindToString(ConversionKind k) { switch (k) { case ConversionKind::Unboxed: return "Unboxed"; From 03a5761630aa1a9f2899c00c87c71d1d86933b4b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 09:47:16 +0000 Subject: [PATCH 2/2] Fix clang-format violations in mapper.cpp Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/6c20d029-898f-4b00-9b30-ac5da459b999 Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com> --- cpp2rust/converter/mapper.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 94a1861c..e0e84c51 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -531,8 +531,9 @@ clang::QualType normalizeQualType(clang::QualType qual_type) { } std::string mapTypeStringRecursive(const std::string &cpp_type) { - auto rule = parallel_search( - types_, [&](const std::string &tpl) { return matchTemplate(tpl, cpp_type); }); + auto rule = parallel_search(types_, [&](const std::string &tpl) { + return matchTemplate(tpl, cpp_type); + }); if (rule == types_.end()) { llvm::errs() << "cpp_type: " << cpp_type << '\n'; assert(0 && "Type is not present in types_");