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

Add explicit keyword for generated constructor #386

Merged
merged 2 commits into from
Dec 11, 2023
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
2 changes: 1 addition & 1 deletion example/cpp/include/ICU4XDataProvider.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/cpp/include/ICU4XFixedDecimal.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/cpp/include/ICU4XFixedDecimalFormatter.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/cpp/include/ICU4XLocale.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/AttrOpaque1.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/AttrOpaque2.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/Bar.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/Float64Vec.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/Foo.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/MyString.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/One.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/Opaque.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/OptionOpaque.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/OptionOpaqueChar.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/RefList.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/RefListParameter.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/ResultOpaque.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/Two.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Foo {
MyStruct get_struct() const;
inline const capi::Foo* AsFFI() const { return this->inner.get(); }
inline capi::Foo* AsFFIMut() { return this->inner.get(); }
inline Foo(capi::Foo* i) : inner(i) {}
inline explicit Foo(capi::Foo* i) : inner(i) {}
Foo() = default;
Foo(Foo&&) noexcept = default;
Foo& operator=(Foo&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyStruct {
std::optional<MyStruct> create() const;
inline const capi::MyStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyStruct* AsFFIMut() { return this->inner.get(); }
inline MyStruct(capi::MyStruct* i) : inner(i) {}
inline explicit MyStruct(capi::MyStruct* i) : inner(i) {}
MyStruct() = default;
MyStruct(MyStruct&&) noexcept = default;
MyStruct& operator=(MyStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MyStruct {
mozilla::Maybe<MyStruct> create() const;
inline const capi::MyStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyStruct* AsFFIMut() { return this->inner.get(); }
inline MyStruct(capi::MyStruct* i) : inner(i) {}
inline explicit MyStruct(capi::MyStruct* i) : inner(i) {}
MyStruct() = default;
MyStruct(MyStruct&&) noexcept = default;
MyStruct& operator=(MyStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MyStruct {
void set_slice(const diplomat::span<const double> new_slice);
inline const capi::MyStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyStruct* AsFFIMut() { return this->inner.get(); }
inline MyStruct(capi::MyStruct* i) : inner(i) {}
inline explicit MyStruct(capi::MyStruct* i) : inner(i) {}
MyStruct() = default;
MyStruct(MyStruct&&) noexcept = default;
MyStruct& operator=(MyStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MyStruct {
void set_slice(const mozilla::Span<const double> new_slice);
inline const capi::MyStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyStruct* AsFFIMut() { return this->inner.get(); }
inline MyStruct(capi::MyStruct* i) : inner(i) {}
inline explicit MyStruct(capi::MyStruct* i) : inner(i) {}
MyStruct() = default;
MyStruct(MyStruct&&) noexcept = default;
MyStruct& operator=(MyStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MyStruct {
void set_str(const std::string_view new_str);
inline const capi::MyStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyStruct* AsFFIMut() { return this->inner.get(); }
inline MyStruct(capi::MyStruct* i) : inner(i) {}
inline explicit MyStruct(capi::MyStruct* i) : inner(i) {}
MyStruct() = default;
MyStruct(MyStruct&&) noexcept = default;
MyStruct& operator=(MyStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MyStruct {
uint8_t write_no_rearrange(capi::DiplomatWriteable& out) const;
inline const capi::MyStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyStruct* AsFFIMut() { return this->inner.get(); }
inline MyStruct(capi::MyStruct* i) : inner(i) {}
inline explicit MyStruct(capi::MyStruct* i) : inner(i) {}
MyStruct() = default;
MyStruct(MyStruct&&) noexcept = default;
MyStruct& operator=(MyStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MyStruct {
void set_b(uint8_t b);
inline const capi::MyStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyStruct* AsFFIMut() { return this->inner.get(); }
inline MyStruct(capi::MyStruct* i) : inner(i) {}
inline explicit MyStruct(capi::MyStruct* i) : inner(i) {}
MyStruct() = default;
MyStruct(MyStruct&&) noexcept = default;
MyStruct& operator=(MyStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Foo {
Bar to_bar() const;
inline const capi::Foo* AsFFI() const { return this->inner.get(); }
inline capi::Foo* AsFFIMut() { return this->inner.get(); }
inline Foo(capi::Foo* i) : inner(i) {}
inline explicit Foo(capi::Foo* i) : inner(i) {}
Foo() = default;
Foo(Foo&&) noexcept = default;
Foo& operator=(Foo&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MyOpaqueStruct {
public:
inline const capi::MyOpaqueStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyOpaqueStruct* AsFFIMut() { return this->inner.get(); }
inline MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
inline explicit MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
MyOpaqueStruct() = default;
MyOpaqueStruct(MyOpaqueStruct&&) noexcept = default;
MyOpaqueStruct& operator=(MyOpaqueStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MyOpaqueStruct {
public:
inline const capi::MyOpaqueStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyOpaqueStruct* AsFFIMut() { return this->inner.get(); }
inline MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
inline explicit MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
MyOpaqueStruct() = default;
MyOpaqueStruct(MyOpaqueStruct&&) noexcept = default;
MyOpaqueStruct& operator=(MyOpaqueStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MyOpaqueStruct {
public:
inline const capi::MyOpaqueStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyOpaqueStruct* AsFFIMut() { return this->inner.get(); }
inline MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
inline explicit MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
MyOpaqueStruct() = default;
MyOpaqueStruct(MyOpaqueStruct&&) noexcept = default;
MyOpaqueStruct& operator=(MyOpaqueStruct&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MyOpaqueStruct {
public:
inline const capi::MyOpaqueStruct* AsFFI() const { return this->inner.get(); }
inline capi::MyOpaqueStruct* AsFFIMut() { return this->inner.get(); }
inline MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
inline explicit MyOpaqueStruct(capi::MyOpaqueStruct* i) : inner(i) {}
MyOpaqueStruct() = default;
MyOpaqueStruct(MyOpaqueStruct&&) noexcept = default;
MyOpaqueStruct& operator=(MyOpaqueStruct&& other) noexcept = default;
Expand Down
2 changes: 1 addition & 1 deletion tool/src/cpp/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn gen_struct<W: fmt::Write>(

writeln!(
&mut public_body,
"inline {}(capi::{}* i) : inner(i) {{}}",
"inline explicit {}(capi::{}* i) : inner(i) {{}}",
opaque.name, opaque.name
)?;
writeln!(
Expand Down
Loading