tbv2: use std::decay_t in make_field

CodeGen v2 permits template parameters to be qualified. This means that if we
call `make_field` with a template parameter it will be qualified. However, we
don't qualify the types when generating meta functions such as `NameProvider`
and `TypeHandler`. This means these qualified types don't match up with the
expected type.

Use `std::decay_t` when forwarding the type to `NameProvider` and `TypeHandler`
so they're always the base type that they were generated with.

Test Plan:
- CI
- Added a test for `std::unique_ptr<const Foo>` to exercise this. Failed
  before, passes after.
This commit is contained in:
Jake Hillion 2023-12-22 12:59:02 +00:00
parent beb404e41c
commit 2a9fc0f00a
2 changed files with 52 additions and 3 deletions

View File

@ -1072,9 +1072,9 @@ constexpr inst::Field make_field(std::string_view name) {
sizeof(T),
ExclusiveSizeProvider<T>::size,
name,
NameProvider<T>::names,
TypeHandler<Ctx, T>::fields,
TypeHandler<Ctx, T>::processors,
NameProvider<std::decay_t<T>>::names,
TypeHandler<Ctx, std::decay_t<T>>::fields,
TypeHandler<Ctx, std::decay_t<T>>::processors,
};
}
)";

View File

@ -31,6 +31,31 @@ definitions = '''
}
]
'''
[cases.unique_ptr_const_uint64_empty]
param_types = ["std::unique_ptr<const std::uint64_t>&"]
setup = "return {nullptr};"
expect_json = '''
[
{
"staticSize": 8,
"dynamicSize": 0,
"exclusiveSize": 8,
"length": 0,
"capacity": 1,
"elementStaticSize": 8
}
]
'''
expect_json_v2 = '''
[
{
"staticSize": 8,
"exclusiveSize": 8,
"length": 0,
"capacity": 1
}
]
'''
[cases.unique_ptr_uint64_present]
param_types = ["std::unique_ptr<std::uint64_t>&"]
setup = "return {std::make_unique<std::uint64_t>(64)};"
@ -181,6 +206,30 @@ definitions = '''
}
]
'''
[cases.shared_ptr_const_uint64_empty]
param_types = ["std::shared_ptr<const std::uint64_t>&"]
setup = "return {nullptr};"
expect_json = '''
[
{
"staticSize": 16,
"dynamicSize": 0,
"length": 0,
"capacity": 1,
"elementStaticSize": 8
}
]
'''
expect_json_v2 = '''
[
{
"staticSize": 16,
"exclusiveSize": 16,
"length": 0,
"capacity": 1
}
]
'''
[cases.shared_ptr_uint64_present]
param_types = ["std::shared_ptr<std::uint64_t>&"]
setup = "return std::make_shared<std::uint64_t>(64);"