Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover C++20 in CI (fixing char8_t-related problem there). #1437

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
matrix:
rust: [nightly, beta, stable, 1.82.0, 1.77.0, 1.74.0, 1.73.0]
os: [ubuntu]
flags: ['']
include:
- name: Cargo on macOS
rust: nightly
Expand All @@ -31,6 +32,18 @@ jobs:
rust: nightly-x86_64-pc-windows-msvc
os: windows
flags: /EHsc
- name: C++14
rust: nightly
os: ubuntu
flags: -std=c++14
anforowicz marked this conversation as resolved.
Show resolved Hide resolved
- name: C++17
rust: nightly
os: ubuntu
flags: -std=c++17
- name: C++20
rust: nightly
os: ubuntu
flags: -std=c++20
env:
CXXFLAGS: ${{matrix.flags}}
RUSTFLAGS: --cfg deny_warnings -Dwarnings
Expand Down
7 changes: 7 additions & 0 deletions include/cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class String final {
String(const char *, std::size_t);
String(const char16_t *);
String(const char16_t *, std::size_t);
#if __cplusplus >= 202002L
// `reinterpret_cast` of `const char*` into `const char8_t*` is dangerous,
// because `const char*` may point to non-UTF8. OTOH, conversion in the
// other direction seems safe.
String(const char8_t *s) : String(reinterpret_cast<const char*>(s)) {}
String(const char8_t *s, std::size_t len) : String(reinterpret_cast<const char*>(s), len) {}
#endif

// Replace invalid Unicode data with the replacement character (U+FFFD).
static String lossy(const std::string &) noexcept;
Expand Down
3 changes: 2 additions & 1 deletion tests/ffi/tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,8 @@ extern "C" const char *cxx_run_test() noexcept {
ASSERT(cstr == "foo");
ASSERT(other_cstr == "test");

const char *utf8_literal = u8"Test string";
// `u8"foo"` is `const char*` before, and `const char8_t*` after C++ 20, so using `auto`.
const auto *utf8_literal = u8"Test string";
const char16_t *utf16_literal = u"Test string";
rust::String utf8_rstring = utf8_literal;
rust::String utf16_rstring = utf16_literal;
Expand Down
Loading