boostorg / boostorg/pfr

Errors for classes with empty base(s), C++17

Open
#36 2 comments 0 reactions 1 assignee Claimed by @apolukhin View on GitHub
bug compiler-or-standard-limitation
Dominant language
C++
Stars
1.5k
Forks
176
Avg merge
5d 21h
Merged PRs (30d)
1

Description

Provided the following hierarchy of classes:

```C++
namespace empty_base {

struct A {};
struct B {};

// Empty base, no members
struct C : A {};
// Empty base, some members
struct D : A { double d; };
// Two empty bases, no members
struct E : A, B {};
// Two empty bases, some membes
struct F : A, B { float f; };

}
```

When trying to use pfr with them there are the following errors (the error messages are somewhat shortened):

**_Class with an empty base and no members_**
_Precise:_
```C++
> decltype(structure_to_tuple(declval()))
./include/boost/pfr/detail/core17_generated.hpp:39:9: fatal error: type 'const empty_base::C' decomposes into 0 elements, but 1 names were provided
auto& [a] = val;
^
./include/boost/pfr/detail/core17_generated.hpp:1037:30: note: in instantiation of function template specialization 'boost::pfr::detail::tie_as_tuple' requested here
return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{});
^
./include/boost/pfr/precise/core.hpp:93:17: note: in instantiation of function template specialization 'boost::pfr::detail::tie_as_tuple' requested here
detail::tie_as_tuple(val),
```
_Flat:_
```C++
> decltype(flat_structure_to_tuple(declval()))
std::tuple<> // This is fine, actually
```

**_Class with an empty base and some members_**
_Presize:_
```C++
> decltype(structure_to_tuple(declval()))
./include/boost/pfr/detail/core17_generated.hpp:52:9: fatal error: type 'const empty_base::D' decomposes into 1 elements, but 2 names were provided
auto& [a,b] = val;
^
./include/boost/pfr/detail/core17_generated.hpp:1037:30: note: in instantiation of function template specialization 'boost::pfr::detail::tie_as_tuple' requested here
return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{});
^
./include/boost/pfr/precise/core.hpp:93:17: note: in instantiation of function template specialization 'boost::pfr::detail::tie_as_tuple' requested here
detail::tie_as_tuple(val)
```
_Flat:_
```C++
> decltype(flat_structure_to_tuple(declval()))
./include/boost/pfr/detail/offset_based_getter.hpp:63:3: fatal error: static_assert failed "====================> Boost.PFR: Member sequence does not indicate correct size for struct type!"
static_assert(sizeof(U) == sizeof(S), "====================> Boost.PFR: Member sequence does not indicate correct size for struct type!");
// Nice assert, but doesn't help, actually
```

**_Class with two empty bases and no members_**
_Precise:_
```C++
> decltype(structure_to_tuple(declval()))
./include/boost/pfr/detail/core17_generated.hpp:52:9: fatal error: type 'const empty_base::E' decomposes into 0 elements, but 2 names were provided
auto& [a,b] = val;
```
_Flat:_
```C++
> decltype(flat_structure_to_tuple(declval()))
./include/boost/pfr/detail/offset_based_getter.hpp:63:3: fatal error: static_assert failed "====================> Boost.PFR: Member sequence does not indicate correct size for struct type!"
static_assert(sizeof(U) == sizeof(S), "====================> Boost.PFR: Member sequence does not indicate correct size for struct type!");
```

**_Class with two empty bases and some members_**
_Precise:_
```C++
> decltype(structure_to_tuple(declval()))
./include/boost/pfr/detail/core17_generated.hpp:58:9: fatal error: type 'const empty_base::F' decomposes into 1 elements, but 3 names were provided
auto& [a,b,c] = val;
```
_Flat:_
```C++
> decltype(flat_structure_to_tuple(declval()))
./include/boost/pfr/detail/offset_based_getter.hpp:63:3: fatal error: static_assert failed "====================> Boost.PFR: Member sequence does not indicate correct size for struct type!"
static_assert(sizeof(U) == sizeof(S), "====================> Boost.PFR: Member sequence does not indicate correct size for struct type!");
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.