google / google/flatbuffers

Current release: generated code variables collision (possible regression)

Open
#9,066 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
26.5k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

Between release (25.9.23) and current release (25.12.19) I stopped being able to compile my flatbuffers into C/C++ headers, so I count it as possible regression. I use Gentoo, and current release appeared in stable packages recently, therefore I had not noticed before.

geometry.fbs
```
namespace flatbuff;
namespace flatbuff.twm;
table D3_t {
x:int;
y:int;
z:int;
}
table track_line_t {
A:twm.D3_t;
B:twm.D3_t;
}

namespace flatbuff.twm.wrappers_geometry_t;
table dummy {
val:byte;
}

namespace flatbuff.twm;
union geometry_t {
dummy:wrappers_geometry_t.dummy,
line:twm.track_line_t,
}

namespace flatbuff;
```

```
$ flatc --cpp geometry.fbs

warning:
/tmp/geometry.fbs:10: 5: warning: field names should be lowercase snake_case, got: A
/tmp/geometry.fbs:11: 5: warning: field names should be lowercase snake_case, got: B
```

(It was legacy code that was converted to flatbuffers, so that's why snake_case had not been used and original field names were kept instead. Hence the warning.)

```
$ cat geometry_generated.h
...
struct track_line_t FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
...
template
bool Verify(::flatbuffers::VerifierTemplate &verifier) const {
return VerifyTableStart(verifier) &&
VerifyOffset(verifier, VT_A) &&
verifier.VerifyTable(A()) &&
VerifyOffset(verifier, VT_B) &&
verifier.VerifyTable(B()) &&
verifier.EndTable();
}
};
...
```

The `B` in `template ` and `VerifierTemplate` is in conflict with `verifier.VerifyTable(B())`.
It would be better to use different name for `bool B` variable. Preferably something, that is not likely to collide with field names (maybe something with underscore or different valid special characters?).

Compilation output:
```
/opt/include/geometry_generated.h: In member function ‘bool flatbuff::twm::track_line_t::Verify(flatbuffers::VerifierTemplate&) const’:
/opt/include/geometry_generated.h:162:34: error: expression cannot be used as a function
162 | verifier.VerifyTable(B()) &&
| ~^~
```

As stated above, with previous versions of flatbuffers it worked.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.