Skip to content

[ntuple] Wrong alignment with transient class member #16765

@hahnjo

Description

@hahnjo

Description

RClassField::Attach only takes into account persistent members to determine alignment:

void ROOT::Experimental::RClassField::Attach(std::unique_ptr<RFieldBase> child, RSubFieldInfo info)
{
fMaxAlignment = std::max(fMaxAlignment, child->GetAlignment());
fSubFieldsInfo.push_back(info);
RFieldBase::Attach(std::move(child));
}

Reproducer

#include <ROOT/RField.hxx>

class ClassWithTransient {
  char a;
  int t; //!
  char b;
};

void ntuple_class_align() {
  ROOT::Experimental::RField<ClassWithTransient> f("f");
  std::cout << "value size: " << f.GetValueSize() << ", alignment: " << f.GetAlignment() << "\n";
}

output:

Processing ntuple_class_align.C...
value size: 12, alignment: 1

This can lead to problems if such class is embedded into a record, for example a std::pair.

Metadata

Metadata

Assignees

Type

No type
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