after that, there are still some errors remaining.
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp: In member function ‘void flatbuffers::Parser::ParseDecl()’:
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:801: error: expected primary-expression before ‘[’ token
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:801: error: expected primary-expression before ‘]’ token
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:801: error: expected primary-expression before ‘const’
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:801: error: expected primary-expression before ‘const’
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:801: error: expected unqualified-id before ‘bool’
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:819: error: expected primary-expression before ‘[’ token
cc1plus: warnings being treated as errors
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:819: error: left-hand operand of comma has no effect
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:819: error: expected primary-expression before ‘const’
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:820: error: expected primary-expression before ‘basetype’
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:820: error: unable to deduce ‘auto’ from ‘<expression error>’
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:820: error: expected ‘,’ or ‘;’ before ‘{’ token
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:819: error: unused variable ‘CheckClash’
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algobase.h:66,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/algorithm:61,
from /data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:17:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U1 = flatbuffers::Value, _U2 = long int, _T1 = flatbuffers::Value, _T2 = flatbuffers::FieldDef*]’:
/data/home/johnnydai/personal/flatbuffers-master/src/idl_parser.cpp:549: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:107: error: invalid conversion from ‘long int’ to ‘flatbuffers::FieldDef*’
For the first error, the code is:
std::sort(fields.begin(), fields.end(),
[](const FieldDef *a, const FieldDef *b) -> bool {
auto a_id = atoi(a->attributes.Lookup("id")->constant.c_str());
auto b_id = atoi(b->attributes.Lookup("id")->constant.c_str());
return a_id < b_id;
});
And I modify this to:
bool cmp_fields(const FieldDef *a, const FieldDef *b)
{
auto a_id = atoi(a->attributes.Lookup("id")->constant.c_str());
auto b_id = atoi(b->attributes.Lookup("id")->constant.c_str());
return a_id < b_id;
}
std::sort(fields.begin(), fields.end(), &cmp_fields);
and then it works.
For the second error, the code is:
auto CheckClash = [&fields, &struct_def](const char *suffix,
BaseType basetype) {
auto len = strlen(suffix);
for (auto it = fields.begin(); it != fields.end(); ++it) {
auto &name = (*it)->name;
if (name.length() > len &&
name.compare(name.length() - len, len, suffix) == 0 &&
(*it)->value.type.base_type != BASE_TYPE_UTYPE) {
auto field = struct_def.fields.Lookup(
name.substr(0, name.length() - len));
if (field && field->value.type.base_type == basetype)
Error("Field " + name +
" would clash with generated functions for field " +
field->name);
}
}
};
I think these kind of errors are caused because of my compiler, its version is too low to support the advanced grammars of cpp.