Skip to content

Support src.cpp and src.c in the same rules dir#92

Merged
nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:rules-src
May 13, 2026
Merged

Support src.cpp and src.c in the same rules dir#92
nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:rules-src

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 13, 2026

For C string functions, C++ defines const overloads. For example, in C, strchr is defined as:

char *strchr(const char *s, int c);

In C++, it's overloaded as:

const char *strchr(const char *s, int c);
char *strchr(char *s, int c);

Writing char *f5(const char *a0, int a1) { return strchr(a0, a1); } would result in the following error:

error: cannot initialize return object of type 'char *' with an rvalue of type 'const char *'
    6 | char *f6(const char *a0, int a1) { return strchr(a0, a1); }

For this reason, parse both src.cpp and src.c in a rules dir. src.c keeps C specific rules and src.cpp keeps C++ specific rules. The function names in the 2 functions cannot collide, cpp-rule-preprocessor checks against colliding names.

@lucic71 lucic71 changed the title Support src.cpp and src. in the same rules dir Support src.cpp and src.c in the same rules dir May 13, 2026
Comment thread cpp2rust/cpp_rule_preprocessor.cpp Outdated
llvm::json::Object file_root;
cpp2rust::Extract(path, file_root);
for (auto &[k, v] : file_root) {
if (root.find(k) != root.end()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!root.try_emplace(k, v).second

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nunoplopes nunoplopes merged commit 8802f62 into Cpp2Rust:master May 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants