Skip to content

Translate concepts and requires expressions - #347

Open
lucic71 wants to merge 8 commits into
Cpp2Rust:masterfrom
lucic71:concepts
Open

lucic71 wants to merge 8 commits into
Cpp2Rust:masterfrom
lucic71:concepts

Conversation

@lucic71

@lucic71 lucic71 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

They are evaluated by clang. Only the result of the evaluation is translated.

Furthermore, static_assert is no-op because it's evaluated at compile time. Same for concept declaration.

@nunoplopes

Copy link
Copy Markdown
Contributor

It would be nice to translate these statements rather than constant fold at compile time.

@lucic71

lucic71 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

It would be nice to translate these statements rather than constant fold at compile time.

I think i can keep static_asserts, concepts and requires would be too difficult to keep now.

@lucic71

lucic71 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

It would be nice to translate these statements rather than constant fold at compile time.

Done, I translate static_assert as const assert in Rust.

For the things that can be const evaluated in rust I keep the expression inside static_assert, e.g. const _: () = assert!(size_of(int) == 4).

For the things that cannot be const-evaluated (non-const Rust functions) or for the things that don't have a direct translation to Rust (concepts and requires) I write: const _: () = assert!(true, "Small<int>") to keep track of the C++ expression that generated the code.

This branch has not been deployed

No deployments
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