Skip to content

Generated C++ code for variable length data may not compile  #796

Closed
@rogerorr

Description

@rogerorr

There seems to be a potential case mismatch when using a schema file with a variable length field.

There is inconsistent handling of the case of the first letter of the field name.

The C++ generated code creates an accessor method such as:
static SBE_CONSTEXPR std::uint64_t exampleHeaderLength() SBE_NOEXCEPT
but then attempts to call it inside:
SBE_NODISCARD static size_t computeLength(std::size_t ExampleLength = 0)
by invoking it as:
length += ExampleHeaderLength();

I encountered the issue updating from 1.12.2 to 1.82.2 and have reproduced it with the current code by changing the case of the last field in sbe-tool/src/test/resources/code-generation-schema.xml from "color" to "Color":

java -Dsbe.target.language=CPP -Dsbe.target.namespace=test -jar sbe-all/build/libs/sbe-all-1.19.0-SNAPSHOT.jar sbe-tool/src/test/resources/code-generation-schema.xml

Testing the output:

g++ -c test/Car.h
test/car.h: In static member function 'static size_t test::Car::computeLength(const std::vector<std::tuple<long unsigned int> >&, const std::vector<std::tuple<long unsigned int> >&, std::size_t, std::size_t, std::size_t, std::size_t)':
test/car.h:3202:15: error: 'ColorHeaderLength' was not declared in this scope; did you mean 'colorHeaderLength'?
 3202 |     length += ColorHeaderLength();
      |               ^~~~~~~~~~~~~~~~~
      |               colorHeaderLength

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions