From 3dbdced3414d0e2118c9be930e9f59a742fb819f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 1 May 2026 13:28:46 +0100 Subject: [PATCH 1/2] Avoid reserved keyword and include next warnings --- cpp2rust/compat/arpa/inet.h | 16 ++++++++-------- cpp2rust/compat/assert.h | 4 ++-- cpp2rust/compat/platform_flags.h | 1 + rules/assert/src.cpp | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cpp2rust/compat/arpa/inet.h b/cpp2rust/compat/arpa/inet.h index 44e0c03..e1d7fc1 100644 --- a/cpp2rust/compat/arpa/inet.h +++ b/cpp2rust/compat/arpa/inet.h @@ -8,12 +8,12 @@ #undef htonl #undef htons -uint32_t __cpp2rust_ntohl(uint32_t x); -uint16_t __cpp2rust_ntohs(uint16_t x); -uint32_t __cpp2rust_htonl(uint32_t x); -uint16_t __cpp2rust_htons(uint16_t x); +uint32_t cpp2rust_ntohl(uint32_t x); +uint16_t cpp2rust_ntohs(uint16_t x); +uint32_t cpp2rust_htonl(uint32_t x); +uint16_t cpp2rust_htons(uint16_t x); -#define ntohl(x) __cpp2rust_ntohl(x) -#define ntohs(x) __cpp2rust_ntohs(x) -#define htonl(x) __cpp2rust_htonl(x) -#define htons(x) __cpp2rust_htons(x) +#define ntohl(x) cpp2rust_ntohl(x) +#define ntohs(x) cpp2rust_ntohs(x) +#define htonl(x) cpp2rust_htonl(x) +#define htons(x) cpp2rust_htons(x) diff --git a/cpp2rust/compat/assert.h b/cpp2rust/compat/assert.h index a06ef79..a418218 100644 --- a/cpp2rust/compat/assert.h +++ b/cpp2rust/compat/assert.h @@ -9,6 +9,6 @@ #include #endif -void __cpp2rust_assert_fail(bool condition) __attribute__((noreturn)); +void cpp2rust_assert_fail(bool condition) __attribute__((noreturn)); -#define assert(expr) __cpp2rust_assert_fail(expr) +#define assert(expr) cpp2rust_assert_fail(expr) diff --git a/cpp2rust/compat/platform_flags.h b/cpp2rust/compat/platform_flags.h index 063449a..9e59140 100644 --- a/cpp2rust/compat/platform_flags.h +++ b/cpp2rust/compat/platform_flags.h @@ -11,6 +11,7 @@ static inline std::vector getPlatformClangFlags() { "-resource-dir=" CLANG_RESOURCE_DIR, "-I" COMPAT_INCLUDE_DIR, "-D_FORTIFY_SOURCE=0", + "-Wno-gnu-include-next", }; #ifdef MACOS_SDK_PATH flags.push_back("-isysroot" MACOS_SDK_PATH); diff --git a/rules/assert/src.cpp b/rules/assert/src.cpp index 0e80c09..6aae00d 100644 --- a/rules/assert/src.cpp +++ b/rules/assert/src.cpp @@ -4,5 +4,5 @@ #include void f1(bool condition) { - return __cpp2rust_assert_fail(condition); + return cpp2rust_assert_fail(condition); } From de6535e0bc80bc2da1b310570613a2655d1c4a2e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 1 May 2026 13:45:11 +0100 Subject: [PATCH 2/2] Fix include next warning --- cpp2rust/compat/platform_flags.h | 9 +++++++-- cpp2rust/converter/translation_rule.cpp | 6 ++++-- cpp2rust/cpp2rust_lib.cpp | 9 +++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cpp2rust/compat/platform_flags.h b/cpp2rust/compat/platform_flags.h index 9e59140..09ceb59 100644 --- a/cpp2rust/compat/platform_flags.h +++ b/cpp2rust/compat/platform_flags.h @@ -6,15 +6,20 @@ #include #include -static inline std::vector getPlatformClangFlags() { +static inline std::vector getPlatformClangBeginFlags() { std::vector flags = { "-resource-dir=" CLANG_RESOURCE_DIR, "-I" COMPAT_INCLUDE_DIR, "-D_FORTIFY_SOURCE=0", - "-Wno-gnu-include-next", }; #ifdef MACOS_SDK_PATH flags.push_back("-isysroot" MACOS_SDK_PATH); #endif return flags; } + +static inline std::vector getPlatformClangEndFlags() { + return { + "-Wno-gnu-include-next", + }; +} diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index 34315f7..c57b2a4 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -846,8 +846,10 @@ TypeRule ParseTypeRuleJSON(const llvm::json::Object &obj) { void LoadSrc(ExprRules &exprs, TypeRules &types, const std::filesystem::path &src_path) { - clang::tooling::FixedCompilationDatabase compilations( - ".", getPlatformClangFlags()); + auto flags = getPlatformClangBeginFlags(); + auto end_flags = getPlatformClangEndFlags(); + flags.insert(flags.end(), end_flags.begin(), end_flags.end()); + clang::tooling::FixedCompilationDatabase compilations(".", flags); ActionFactory factory(exprs, types); clang::tooling::ClangTool tool(compilations, {src_path.string()}); tool.run(&factory); diff --git a/cpp2rust/cpp2rust_lib.cpp b/cpp2rust/cpp2rust_lib.cpp index 549e161..23402bd 100644 --- a/cpp2rust/cpp2rust_lib.cpp +++ b/cpp2rust/cpp2rust_lib.cpp @@ -15,9 +15,11 @@ std::string TranspileSrc(std::string_view cc_code, Model model, const std::vector &cxx_flags, const std::string &rules_dir, std::string_view filename) { - auto tool_args = getPlatformClangFlags(); + auto tool_args = getPlatformClangBeginFlags(); tool_args.push_back("-fparse-all-comments"); tool_args.insert(tool_args.end(), cxx_flags.begin(), cxx_flags.end()); + auto end_flags = getPlatformClangEndFlags(); + tool_args.insert(tool_args.end(), end_flags.begin(), end_flags.end()); std::string rs_code; clang::tooling::runToolOnCodeWithArgs( @@ -43,7 +45,10 @@ std::string TranspileDir(std::string_view build_dir, Model model, clang::tooling::ClangTool Tool(*compile_dbase, files); Tool.appendArgumentsAdjuster(clang::tooling::getInsertArgumentAdjuster( - getPlatformClangFlags(), clang::tooling::ArgumentInsertPosition::BEGIN)); + getPlatformClangBeginFlags(), + clang::tooling::ArgumentInsertPosition::BEGIN)); + Tool.appendArgumentsAdjuster(clang::tooling::getInsertArgumentAdjuster( + getPlatformClangEndFlags(), clang::tooling::ArgumentInsertPosition::END)); std::string rs_code; FrontendActionFactory factory(rs_code, model, rules_dir);