alibaba / alibaba/yalantinglibs
[struct_xml] struct_xml::to_xml一个包含std::map<int, int>的对象,执行struct_xml::to_xml时崩溃。且不能支持struct_pack::compatible做成员变量
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 327
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 2
Description
代码如下
```
#include
#include
#include "ylt/struct_xml/xml_reader.h"
#include "ylt/struct_xml/xml_writer.h"
#include
struct person {
std::string name;
int age;
std::list list;
std::vector vec;
std::map idx2Int;
//struct_pack::compatible c1;
};
bool operator==(const person& a, const person& b) {
return a.name == b.name && a.age == b.age;
}
YLT_REFL(person, name, list, age, vec, idx2Int/*, c1*/);
int main() {
person p{ "tom", 20 , {1,2,3}, {1,2,3}, { {1, 11}, {2, 21}} /*, 11*/ };
std::string str;
// struct to xml
struct_xml::to_xml(p, str);
std::cout << str << "\n";
// struct from xml
person p1;
struct_xml::from_xml(p1, str);
assert(p1.name == p.name);
return 0;
}
```
问题1,因为person里有成员变量std::map idx2Int,所以执行到struct_xml::to_xml(p, str);时崩溃。崩溃如下图

问题2,如果打开struct_pack::compatible c1;相关的注释,编译不通过,编译报错如下图

因为我想让结构体person同时使用struct_pack、struct_xml、struct_json,且想保证不同版本的前后兼容性。且能支持std常用的容器,如std::map。谢谢!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by compiling and running the supplied reproduction with ylt/struct_xml/xml_reader.h, ylt/struct_xml/xml_writer.h, and ylt/struct_pack.hpp. Trace struct_xml::to_xml(p, str) with std::map, then retry with struct_pack::compatible enabled and inspect the compiler diagnostics. Done means the reported map crash and compatible-member compilation failure are resolved without breaking the shown XML round trip.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100