flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[C++] Incorrect Namespace Resolution for Root Table in Generated VerifyBuffer Code

Open ChristophKarlHeck opened this issue 1 year ago • 0 comments

Hi, I got the following error when I used flatbuffers version 24.3.25 in C++. Here are the steps to reproduce:

  1. FlatBuffers Schema: Here is the schema (serial_mail.fbs) that reproduces the issue:
namespace SerialMail;

// Define a struct for the 3-byte array
struct Value {
  data_0: uint8;
  data_1: uint8;
  data_2: uint8;  
}

// Main table
table SerialMail {
  inputs: [Value];                 // Vector of raw data
  classification: [float];         // List of classifications
  classification_active: bool;
  channel: bool;
}

root_type SerialMail;
  1. FlatBuffers Compiler: I compiled this schema using the following command:
flatc --cpp serial_mail.fbs
  1. Generated Code: In the generated header (serial_mail_generated.h), the following line of code was produced:
return verifier.VerifyBuffer<SerialMail::SerialMail>(nullptr);

This leads to a compilation error:

[build] /libs/flatbuffers/include/flatbuffers/verifier.h:245:29: note:   template argument deduction/substitution failed:
[build] /include/serializing_data/serial_mail_generated.h:151:55: error: type/value mismatch at argument 1 in template parameter list for 'template<class T> bool flatbuffers::VerifierTemplate<TrackVerifierBufferSize>::VerifyBuffer(const char*) [with bool TrackVerifierBufferSize = false]'
[build]   151 |   return verifier.VerifyBuffer<SerialMail::SerialMail>(nullptr);
[build]       |    
  1. I had to manually adjust the VerifyBuffer as follows:
return verifier.VerifyBuffer<SerialMail>(nullptr);

The issue seems to be related to how the namespace and root table are resolved in the generated code. If this is not a bug, I would appreciate guidance on whether the schema or build process needs adjustment.

Cheers, Christoph

ChristophKarlHeck avatar Nov 26 '24 10:11 ChristophKarlHeck