Gerrit0 opened a new pull request, #2927:
URL: https://github.com/apache/avro/pull/2927
## What is the purpose of the change
I have a schema which contains a few empty records within a union to
describe operations which don't require options (other records in the union do
have fields). When generating code from the avro schema for an empty record
like the following:
```json
{
"type": "record",
"name": "Empty",
"fields": []
}
```
avrogencpp creates:
```cpp
template<> struct codec_traits<empty::Empty> {
static void encode(Encoder& e, const empty::Empty& v) {
}
static void decode(Decoder& d, empty::Empty& v) {
if (avro::ResolvingDecoder *rd =
dynamic_cast<avro::ResolvingDecoder *>(&d)) {
const std::vector<size_t> fo = rd->fieldOrder();
for (std::vector<size_t>::const_iterator it = fo.begin();
it != fo.end(); ++it) {
switch (*it) {
default:
break;
}
}
} else {
}
}
};
```
In a project with compiler warnings turned up, this generates compiler
warnings for unused parameters (GCC's `-Wunused-parameter`, MSVC's C4100) and
also for the switch with a default case but no other cases (some MSVC option
that I don't have in front of me right now).
With this change, we instead generate the following, which compiles cleanly:
```cpp
template<> struct codec_traits<empty::Empty> {
static void encode(Encoder&, const empty::Empty&) {}
static void decode(Decoder&, empty::Empty&) {}
};
```
## Verifying this change
This change is already covered by existing tests, the
[empty_record](https://github.com/apache/avro/blob/main/lang/c%2B%2B/jsonschemas/empty_record)
schema is compiled as a part of building the C++ SDK, and continues to
compile, producing the output described above.
## Documentation
- Does this pull request introduce a new feature? No.
- If yes, how is the feature documented? N/A
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]