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

C++ clang error casting const pointer #309

Open
coltfred opened this issue Apr 16, 2020 · 6 comments · May be fixed by #310
Open

C++ clang error casting const pointer #309

coltfred opened this issue Apr 16, 2020 · 6 comments · May be fixed by #310
Labels
bug C++ C++ only related issues

Comments

@coltfred
Copy link
Contributor

When I generate C++ code g++ seems to compile it fine, but clang on the other hand produces errors that look like this:

/home/colt/src/coltfred/ironoxide-java/cpp/generated/sdk/IronOxide_impl.hpp:116:27: error: assigning to 'void *' from incompatible type 'const DeviceIdOpaque *'
            a0.val.data = static_cast<const DeviceIdOpaque *>((*deviceId));
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@coltfred coltfred linked a pull request Apr 16, 2020 that will close this issue
@Dushistov
Copy link
Owner

Dushistov commented Apr 16, 2020

Without context it was completly unclear what is going on. What source code for IronOxide?

Edit: I am asking, because of CI run all three major C++ compiler: gcc/linux, clang/macos and mcvs/windows. So it should catch such kind of issue.

@coltfred
Copy link
Contributor Author

So we have something like:

foreigner_class!(
/// ID of a user. Unique with in a segment. Must match the regex `^[a-zA-Z0-9_.$#|@/:;=+'-]+$`.
#[derive(Clone)]
class UserId {
    self_type UserId;
    private constructor = empty;
    static_method user_id::validate(s: &str) -> Result<UserId, String>;
    method user_id::id(&self) -> String; alias getId;
});

and then

foreigner_class!(
/// Options for group creation.
class GroupCreateOpts {
    self_type GroupCreateOpts;
    constructor GroupCreateOpts::default() -> GroupCreateOpts;
    constructor group_create_opts::create(id: Option<&GroupId>, name: Option<&GroupName>, addAsAdmin: bool, addAsMember: bool, owner: Option<&UserId>, admins: Vec<UserId>, members: Vec<UserId>, needsRotation: bool) -> GroupCreateOpts;
});

The code generated in that constructor is what is the problem:

    GroupCreateOptsWrapper(boost::optional<const GroupId &> id, boost::optional<const GroupName &> name, bool addAsAdmin, bool addAsMember, boost::optional<const UserId &> owner, RustForeignVecUserId admins, RustForeignVecUserId members, bool needsRotation) noexcept
    {
        struct CRustOption4232const3232c_void a0;
        if (!!id) {
            a0.val.data = static_cast<const GroupIdOpaque *>((*id));
            a0.is_some = 1;
        } else {
            a0.is_some = 0;
        }        struct CRustOption4232const3232c_void a1;
        if (!!name) {
            a1.val.data = static_cast<const GroupNameOpaque *>((*name));
            a1.is_some = 1;
        } else {
            a1.is_some = 0;
        }        struct CRustOption4232const3232c_void a4;
        if (!!owner) {
            a4.val.data = static_cast<const UserIdOpaque *>((*owner));
            a4.is_some = 1;
        } else {
            a4.is_some = 0;
        }
        this->self_ = GroupCreateOpts_create(std::move(a0), std::move(a1), addAsAdmin ? 1 : 0, addAsMember ? 1 : 0, std::move(a4), admins.release(), members.release(), needsRotation ? 1 : 0);
        if (this->self_ == nullptr) {
            std::abort();
        }
    }

If you want to run this yourself you can go over to https://github.com/IronCoreLabs/ironoxide-java - The branch cpp-initial has the code on it. (follow the build instructions in cpp/BUILDING.md`).

@Dushistov
Copy link
Owner

@coltfred

There is no branch 'cpp-initial' in https://github.com/IronCoreLabs/ironoxide-java ,
may be you mean cpp-swig-test?

@coltfred
Copy link
Contributor Author

coltfred commented Apr 20, 2020 via email

@Dushistov
Copy link
Owner

After 1835ebd your example should compile just fine. Because of for Option<& Class> std/boost :: optional is not used anymore. But I would like to leave it as open to fix const void * hack.

@Dushistov Dushistov added bug C++ C++ only related issues labels Apr 20, 2020
@Dushistov
Copy link
Owner

And also there is a lot of problem related to C++ classes dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug C++ C++ only related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants