ctest icon indicating copy to clipboard operation
ctest copied to clipboard

Not clear how to test `const <type> <obj>;` fields

Open quodlibetor opened this issue 7 years ago • 2 comments

See this comment in git2-rs for details: https://github.com/alexcrichton/git2-rs/pull/315#issuecomment-393006101

quodlibetor avatar May 30 '18 21:05 quodlibetor

Given:

// rust
#[repr(C)]
struct Foo {
  pub bar: i32
}

and

// c
struct Foo {
   const int32_t bar;
};

the Rust code does not expose any information about whether the C field is cv-qualified or not. That is, I don't think we can generate appropriate C tests for the struct field type just from only looking at the Rust code.

We could, conservatively, assume that C struct fields are always const qualified. I've implemented that approach in #41 .

This won't, however, work if the C struct fields are cv-qualified in general. Maybe we could add a way in the future to specify that certain fields from certain structs are cv-qualified, e.g., via a method to the test generator.

Maybe someday we could replace most methods with attributes:

// rust
#[repr(C)]
struct Foo {
  #[cfg_attr(ctest, const_qualified)]
  pub bar: i32
}

gnzlbg avatar Oct 16 '18 16:10 gnzlbg

I think a better idea is to expose a method in the builder that allows you to tell ctest that a particular field of a struct is cv-qualified. That shouldn't be to hard to hack in, and I think we already have such a method for volatile.

gnzlbg avatar Jul 29 '19 16:07 gnzlbg