Skip to content

Commit 9a23dc6

Browse files
authored
Silent reserved keyword and include next warnings (#52)
1 parent a7de658 commit 9a23dc6

6 files changed

Lines changed: 29 additions & 16 deletions

File tree

cpp2rust/compat/arpa/inet.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
#undef htonl
99
#undef htons
1010

11-
uint32_t __cpp2rust_ntohl(uint32_t x);
12-
uint16_t __cpp2rust_ntohs(uint16_t x);
13-
uint32_t __cpp2rust_htonl(uint32_t x);
14-
uint16_t __cpp2rust_htons(uint16_t x);
11+
uint32_t cpp2rust_ntohl(uint32_t x);
12+
uint16_t cpp2rust_ntohs(uint16_t x);
13+
uint32_t cpp2rust_htonl(uint32_t x);
14+
uint16_t cpp2rust_htons(uint16_t x);
1515

16-
#define ntohl(x) __cpp2rust_ntohl(x)
17-
#define ntohs(x) __cpp2rust_ntohs(x)
18-
#define htonl(x) __cpp2rust_htonl(x)
19-
#define htons(x) __cpp2rust_htons(x)
16+
#define ntohl(x) cpp2rust_ntohl(x)
17+
#define ntohs(x) cpp2rust_ntohs(x)
18+
#define htonl(x) cpp2rust_htonl(x)
19+
#define htons(x) cpp2rust_htons(x)

cpp2rust/compat/assert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#include <stdbool.h>
1010
#endif
1111

12-
void __cpp2rust_assert_fail(bool condition) __attribute__((noreturn));
12+
void cpp2rust_assert_fail(bool condition) __attribute__((noreturn));
1313

14-
#define assert(expr) __cpp2rust_assert_fail(expr)
14+
#define assert(expr) cpp2rust_assert_fail(expr)

cpp2rust/compat/platform_flags.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string>
77
#include <vector>
88

9-
static inline std::vector<std::string> getPlatformClangFlags() {
9+
static inline std::vector<std::string> getPlatformClangBeginFlags() {
1010
std::vector<std::string> flags = {
1111
"-resource-dir=" CLANG_RESOURCE_DIR,
1212
"-I" COMPAT_INCLUDE_DIR,
@@ -17,3 +17,9 @@ static inline std::vector<std::string> getPlatformClangFlags() {
1717
#endif
1818
return flags;
1919
}
20+
21+
static inline std::vector<std::string> getPlatformClangEndFlags() {
22+
return {
23+
"-Wno-gnu-include-next",
24+
};
25+
}

cpp2rust/converter/translation_rule.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,10 @@ TypeRule ParseTypeRuleJSON(const llvm::json::Object &obj) {
846846

847847
void LoadSrc(ExprRules &exprs, TypeRules &types,
848848
const std::filesystem::path &src_path) {
849-
clang::tooling::FixedCompilationDatabase compilations(
850-
".", getPlatformClangFlags());
849+
auto flags = getPlatformClangBeginFlags();
850+
auto end_flags = getPlatformClangEndFlags();
851+
flags.insert(flags.end(), end_flags.begin(), end_flags.end());
852+
clang::tooling::FixedCompilationDatabase compilations(".", flags);
851853
ActionFactory factory(exprs, types);
852854
clang::tooling::ClangTool tool(compilations, {src_path.string()});
853855
tool.run(&factory);

cpp2rust/cpp2rust_lib.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ std::string TranspileSrc(std::string_view cc_code, Model model,
1515
const std::vector<std::string_view> &cxx_flags,
1616
const std::string &rules_dir,
1717
std::string_view filename) {
18-
auto tool_args = getPlatformClangFlags();
18+
auto tool_args = getPlatformClangBeginFlags();
1919
tool_args.push_back("-fparse-all-comments");
2020
tool_args.insert(tool_args.end(), cxx_flags.begin(), cxx_flags.end());
21+
auto end_flags = getPlatformClangEndFlags();
22+
tool_args.insert(tool_args.end(), end_flags.begin(), end_flags.end());
2123

2224
std::string rs_code;
2325
clang::tooling::runToolOnCodeWithArgs(
@@ -43,7 +45,10 @@ std::string TranspileDir(std::string_view build_dir, Model model,
4345

4446
clang::tooling::ClangTool Tool(*compile_dbase, files);
4547
Tool.appendArgumentsAdjuster(clang::tooling::getInsertArgumentAdjuster(
46-
getPlatformClangFlags(), clang::tooling::ArgumentInsertPosition::BEGIN));
48+
getPlatformClangBeginFlags(),
49+
clang::tooling::ArgumentInsertPosition::BEGIN));
50+
Tool.appendArgumentsAdjuster(clang::tooling::getInsertArgumentAdjuster(
51+
getPlatformClangEndFlags(), clang::tooling::ArgumentInsertPosition::END));
4752

4853
std::string rs_code;
4954
FrontendActionFactory factory(rs_code, model, rules_dir);

rules/assert/src.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
#include <assert.h>
55

66
void f1(bool condition) {
7-
return __cpp2rust_assert_fail(condition);
7+
return cpp2rust_assert_fail(condition);
88
}

0 commit comments

Comments
 (0)