boostorg / boostorg/pfr

Incorrect tuple_size if type contains native array member

Open
#170 1 comment 2 reactions 0 assignees View on GitHub
duplicate help wanted
Dominant language
C++
Stars
1.5k
Forks
176
Avg merge
5d 21h
Merged PRs (30d)
1

Description

Reproduce:
```
struct Foo { int x[2]; };
```
gcc: 13.2.0
compile command: ` g++ -std=c++20 a.cpp -Ipath/to/boost`

Expect:
`expects(boost::pfr::tuple_size_v == 1);`
Actual:
`boost::pfr::tuple_size_v == 2`

Workaround(might be problematic, but works for me):
```patch
diff --git a/include/boost/pfr/detail/fields_count.hpp b/include/boost/pfr/detail/fields_count.hpp
index 8d1354e..04bb89c 100644
--- a/include/boost/pfr/detail/fields_count.hpp
+++ b/include/boost/pfr/detail/fields_count.hpp
@@ -150,11 +150,11 @@ constexpr void* assert_first_not_base(std::index_sequence<>) noexcept
///////////////////// Helper for SFINAE on fields count
template ::value>::type>
constexpr auto enable_if_constructible_helper(std::index_sequence) noexcept
- -> typename std::add_pointer::type;
+ -> typename std::add_pointer::type;

template ::value>::type>
constexpr auto enable_if_constructible_helper(std::index_sequence) noexcept
- -> typename std::add_pointer::type;
+ -> typename std::add_pointer::type;

template (detail::make_index_sequence()) ) >
using enable_if_constructible_helper_t = std::size_t;
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the C++20 example with GCC 13.2.0, then read include/boost/pfr/detail/fields_count.hpp around enable_if_constructible_helper and the workaround shown in the issue. Done means boost::pfr::tuple_size_v reports 1 rather than 2 for a struct containing int x[2].

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.