Skip to content

Current release: generated code variables collision (possible regression) #9066

Description

@art-latal

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 B = false>
  bool Verify(::flatbuffers::VerifierTemplate<B> &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 <bool B = false> and VerifierTemplate<B> 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<B>&) 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions