Skip to content

[ntuple] Wrong alignment with transient class member #16765

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions