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

Error when compiling with raw non-const ptr #14

Closed
cloudhan opened this issue Aug 14, 2020 · 3 comments
Closed

Error when compiling with raw non-const ptr #14

cloudhan opened this issue Aug 14, 2020 · 3 comments

Comments

@cloudhan
Copy link
Contributor

with virtual_<matrix*>
the following code

Click to expand!
#include <iostream>
#include <string>

#include <yorel/yomm2/cute.hpp>

using std::string;
using yorel::yomm2::virtual_;

struct matrix {
    virtual ~matrix() {}
};
struct dense_matrix : matrix {};
struct diagonal_matrix : matrix {};

register_class(matrix);
register_class(dense_matrix, matrix);
register_class(diagonal_matrix, matrix);

declare_method(string, to_json, (virtual_<matrix*>));

define_method(string, to_json, (dense_matrix* m)) {
    return "json for dense matrix ptr...";
}

define_method(string, to_json, (diagonal_matrix* m)) {
    return "json for diagonal matrix ptr...";
}

int main() {
    using std::cout;
    using std::cerr;

    yorel::yomm2::update_methods();

    dense_matrix _a{};
    diagonal_matrix _b{};
    auto a = &_a;
    auto b = &_b;

    #pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"

    cout << to_json(a) << "\n"; // json for dense matrix ptr
    cout << to_json(b) << "\n"; // json for diagonal matrix ptr

    return 0;
}

triggers compiling error

D:\yomm2\examples\matrix.cpp(40,13): warning C4068: unknown pragma [D:\yomm2\build\examples\matrix.vcxproj]
D:\yomm2\include\yorel/yomm2.hpp(961,7): error C2665: 'yorel::yomm2::detail::resolver<1,yorel::yomm2::virtual_<matrix *>>::resolve': none of the 2 overloads could convert all the argument types [D:\yomm2\build\examples\matrix.vcxproj]
D:\yomm2\include\yorel/yomm2.hpp(710,18): message : could be 'void *yorel::yomm2::detail::resolver<1,yorel::yomm2::virtual_<matrix *>>::resolve(const yorel::yomm2::detail::word *,uintptr_t,size_t,const yorel::yomm2::detail::word *,const T &)' [D:\yomm2\build\examples\matrix.vcxproj]
          with
          [
              T=matrix *
          ]
D:\yomm2\include\yorel/yomm2.hpp(692,18): message : or       'void *yorel::yomm2::detail::resolver<1,yorel::yomm2::virtual_<matrix *>>::resolve(const yorel::yomm2::detail::word *,uintptr_t,size_t,yorel::yomm2::detail::word,const T &)' [D:\yomm2\build\examples\matrix.vcxproj]
          with
          [
              T=matrix *
          ]
D:\yomm2\include\yorel/yomm2.hpp(959,1): message : while trying to match the argument list '(yorel::yomm2::detail::word *, uintptr_t, size_t, yorel::yomm2::detail::word, const T *)' [D:\yomm2\build\examples\matrix.vcxproj]
          with
          [
              T=matrix
          ]
D:\yomm2\include\yorel/yomm2.hpp(959): message : while compiling class template member function 'void *yorel::yomm2::detail::method<_yomm2_method_to_json,std::string (yorel::yomm2::virtual_<matrix *>),yorel::yomm2::default_policy>::resolve(yorel::yomm2::policy::hash_factors_in_globals,const T *)' [D:\yomm2\build\examples\matrix.vcxproj]
          with
          [
              T=matrix
          ]
D:\yomm2\include\yorel/yomm2.hpp(955): message : see reference to function template instantiation 'void *yorel::yomm2::detail::method<_yomm2_method_to_json,std::string (yorel::yomm2::virtual_<matrix *>),yorel::yomm2::default_policy>::resolve(yorel::yomm2::policy::hash_factors_in_globals,const T *)' being compiled [D:\yomm2\build\examples\matrix.vcxproj]
          with
          [
              T=matrix
          ]
D:\yomm2\examples\matrix.cpp(19): message : see reference to class template instantiation 'yorel::yomm2::detail::method<_yomm2_method_to_json,std::string (yorel::yomm2::virtual_<matrix *>),yorel::yomm2::default_policy>' being compiled [D:\yomm2\build\examples\matrix.vcxproj]

With const matrix* const dense_matrix* and const diagonal_matrix* all work fine.

@cloudhan
Copy link
Contributor Author

compiler version

Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28806 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

@derpda
Copy link
Contributor

derpda commented Aug 14, 2020

My guess is that YOMM2 is intended for value semantics (which are preferred in general).
I will leave the explanation of the specific error to @jll63 since I still don't understand yomm well enough.

From the example it is not clear that pointer semantics are needed. Might this be a classical XY problem? Why don't you just pass a reference instead?
Not sure if I am being helpful :D

@jll63
Copy link
Owner

jll63 commented Aug 14, 2020

This is indeed a bug. I just pushed a fix. Thanks for the report.

@jll63 jll63 closed this as completed Aug 14, 2020
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

No branches or pull requests

3 participants