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

STRUCT_PACK_REFL regist multi template instantiation class failed in clang #738

Open
bolanbujing opened this issue Aug 8, 2024 · 24 comments
Assignees
Labels
bug Something isn't working

Comments

@bolanbujing
Copy link

bolanbujing commented Aug 8, 2024

FixedHash<20> 是我自定义的类型,data_是成员变量,在2.6.0版本下 STRUCT_PACK_REFL(FixedHash<20>, data_) 没问题
但是我升级到2.8.0版本后,编译报错
error: conflicting types for 'STRUCT_PACK_GET' STRUCT_PACK_REFL(FixedHash<20>, data_)
error: function 'STRUCT_PACK_GET<0>' with deduced return type cannot be used before it is defined
STRUCT_PACK_REFL(FixedHash<20>, data_)
编译器使用的是clang11

@poor-circle
Copy link
Collaborator

抱歉,你说的2.6.0和2.8.0指的是?

@poor-circle
Copy link
Collaborator

0.2.6和0.2.8?

@bolanbujing
Copy link
Author

yalnatings2.6.0 和2.8.0版本
, g++ 编译器下,没这个问题

@bolanbujing
Copy link
Author

0.2.6和0.2.8?
是的,0.2.6和0.2.8,我打错了

@poor-circle
Copy link
Collaborator

yalnatings2.6.0 和2.8.0版本 , g++ 编译器下,没这个问题

我们没有这个版本啊

@poor-circle
Copy link
Collaborator

poor-circle commented Aug 8, 2024

FixedHash<20>这个结构体提供下我看看。如果g++可以clang++不可以,估计要么是编译器bug,要么是用到了低版本编译器不支持的特性。我等下修一下。

@bolanbujing
Copy link
Author

FixedHash<20>这个结构体提供下我看看。估计要么是编译器bug要么是用到了低版本编译器不支持的特性。我等下修一下。
g++ 10.5 没问题,class FixedHash {
private:
std::vector<uint8_t> data_;
}

@poor-circle
Copy link
Collaborator

ok,我稍后会修复这个问题

@bolanbujing
Copy link
Author

今天能修吗,我急着用呢,能不能留个联系方式呀

@poor-circle
Copy link
Collaborator

你能确认下这段代码有没有问题吗:

class person {
 private:
  int age;
  std::string name;

 public:
  auto operator==(const person& rhs) const {
    return age == rhs.age && name == rhs.name;
  }
  person() = default;
  person(int age, const std::string& name) : age(age), name(name) {}
  STRUCT_PACK_FRIEND_DECL(person);
};
STRUCT_PACK_REFL(person, age, name);

@poor-circle
Copy link
Collaborator

你能确认下这段代码有没有问题吗:

class person {
 private:
  int age;
  std::string name;

 public:
  auto operator==(const person& rhs) const {
    return age == rhs.age && name == rhs.name;
  }
  person() = default;
  person(int age, const std::string& name) : age(age), name(name) {}
  STRUCT_PACK_FRIEND_DECL(person);
};
STRUCT_PACK_REFL(person, age, name);

clang10下我测试没问题。你是不是没有加 STRUCT_PACK_FRIEND_DECL这个宏?

@bolanbujing
Copy link
Author

STRUCT_PACK_FRIEND_DECL这个宏我加过了,我在外面,不方便试了

@poor-circle
Copy link
Collaborator

STRUCT_PACK_FRIEND_DECL这个宏我加过了,我在外面,不方便试了

那你先试下上面那段代码序列化会不会出问题吧

@bolanbujing
Copy link
Author

bolanbujing commented Aug 9, 2024

@poor-circle 你给得例子可以编译过,其实我得类型是
`template<size_t N>
class person {
private:
std::array<uint8_t, N> data_;
public:
person() = default;

STRUCT_PACK_FRIEND_DECL(person);
};
STRUCT_PACK_REFL(person<20>, data_);
STRUCT_PACK_REFL(person<50>, data_);`
这个编译不过,麻烦看下是什么原因,如何修改

@poor-circle poor-circle changed the title 2.6.0和2.8.0版本的接口差异 [bug] STRUCT_PACK_REFL regist multi template instantiation class failed Aug 9, 2024
@poor-circle poor-circle added the bug Something isn't working label Aug 9, 2024
@poor-circle poor-circle changed the title [bug] STRUCT_PACK_REFL regist multi template instantiation class failed STRUCT_PACK_REFL regist multi template instantiation class failed Aug 9, 2024
@poor-circle poor-circle self-assigned this Aug 9, 2024
@poor-circle poor-circle changed the title STRUCT_PACK_REFL regist multi template instantiation class failed STRUCT_PACK_REFL regist multi template instantiation class failed in clang Aug 9, 2024
@bolanbujing
Copy link
Author

ylt/struct_pack/unpacker.hpp:912:31: warning: uninitialized variable in a constexpr function is a C++20 extension [-Wc++20-extensions] std::uint64_t sz;
在clang编译器下还有一些像这样没有初始化得告警,麻烦也修下

@bolanbujing
Copy link
Author

@poor-circle DISABLE_TYPE_INFO 这个参数有没有全局设置的方法呢,设置了整个工程生效,因为我很多类,很多地方都要设置,想要统一设置

@poor-circle
Copy link
Collaborator

@poor-circle DISABLE_TYPE_INFO 这个参数有没有全局设置的方法呢,设置了整个工程生效,因为我很多类,很多地方都要设置,想要统一设置

我新增一个设置默认值的功能吧

@bolanbujing
Copy link
Author

@poor-circle 哥们,你太优秀了

@poor-circle
Copy link
Collaborator

@poor-circle DISABLE_TYPE_INFO 这个参数有没有全局设置的方法呢,设置了整个工程生效,因为我很多类,很多地方都要设置,想要统一设置

Fixed by #741

@poor-circle
Copy link
Collaborator

namespace struct_pack {
  //default global config
  constexpr sp_config set_default(sp_config*){ return sp_config::DISABLE_TYPE_INFO; }
}

这样就可以了

@bolanbujing
Copy link
Author

bolanbujing commented Aug 10, 2024

template<size_t N>
class person {
private:
std::array<uint8_t, N> data_;
public:
person() = default;

STRUCT_PACK_FRIEND_DECL(person);
};
STRUCT_PACK_REFL(person<20>, data_);
STRUCT_PACK_REFL(person<50>, data_);

这个例子里,把private改成public,然后去掉STRUCT_PACK_FRIEND_DECL(person);clang是可以编译过的,但是我再加上编译选项
add_compile_options(-Werror)
add_compile_options(-Wall)
add_compile_options(-pedantic)
add_compile_options(-Wextra)
又出现满屏的告警信息,希望你们把这个问题一起改了

@poor-circle
Copy link
Collaborator

考虑到反射系统会基于reflection重构,这部分代码暂时不会修复,等重构完成后再看看问题是否存在

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants