boostorg / boostorg/pfr

Compile failed with field typed `std::optional<Eigen::Matrix3d>`

Open
#193 1 comment 0 reactions 0 assignees View on GitHub
compiler-or-standard-limitation duplicate
Dominant language
C++
Stars
1.5k
Forks
176
Avg merge
5d 21h
Merged PRs (30d)
1

Description

The following code is not compiled:
```c++
# include
# include
# include

...

struct B
{
std::optional a;
} f;

boost::pfr::for_each_field(f, [&](const auto& field, auto index)
{
using type = std::remove_cvref_t;
std::cout << nameof::nameof_full_type() << std::endl;
auto name = boost::pfr::get_name();
std::cout << name << std::endl;
});
```

With the following error:
```
[build] /nix/store/38ibz461pxzsi5jshlhf10qylzfc4vkn-clang-wrapper-18.1.8/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_ATOMIC_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_FILESYSTEM_NO_LIB -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_IOSTREAMS_NO_LIB -DBOOST_SYSTEM_DYN_LINK -DBOOST_SYSTEM_NO_LIB -DFMT_SHARED -DH5_USE_BOOST -DH5_USE_EIGEN -DHIGHFIVE_HAS_CONCEPTS=1 -DMPI_NO_CPPBIND -I/home/chn/repo/nixos/packages/biu/include -isystem /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3 -isystem /nix/store/21fky8f0114kmd1dq3svwsgram9c5f3v-concurrencpp/include/concurrencpp-0.1.7 -g -std=gnu++23 -Wno-gnu-string-literal-operator-template -MD -MT CMakeFiles/test-yaml.dir/test/yaml.cpp.o -MF CMakeFiles/test-yaml.dir/test/yaml.cpp.o.d -o CMakeFiles/test-yaml.dir/test/yaml.cpp.o -c /home/chn/repo/nixos/packages/biu/test/yaml.cpp
[build] In file included from /home/chn/repo/nixos/packages/biu/test/yaml.cpp:1:
[build] In file included from /home/chn/repo/nixos/packages/biu/include/biu.hpp:8:
[build] In file included from /home/chn/repo/nixos/packages/biu/include/biu/eigen.tpp:3:
[build] In file included from /home/chn/repo/nixos/packages/biu/include/biu/eigen.hpp:4:
[build] In file included from /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/Dense:1:
[build] In file included from /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/Core:295:
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/Matrix.h:332:22: error: call to member function '_init1' is ambiguous
[build] 332 | Base::template _init1(x);
[build] | ~~~~~~~~~~~~~~~^~~~~~~~~
[build] /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include/c++/13.3.0/optional:214:8: note: in instantiation of function template specialization 'Eigen::Matrix::Matrix' requested here
[build] 214 | : _M_value(std::forward<_Args>(__args)...)
[build] | ^
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/PlainObjectBase.h:839:30: note: candidate function [with T = boost::pfr::detail::ubiq_lref_constructor]
[build] 839 | EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if< (Base::SizeAtCompileTime!=1 || !internal::is_convertible::value)
[build] | ^
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/PlainObjectBase.h:875:30: note: candidate function [with T = boost::pfr::detail::ubiq_lref_constructor]
[build] 875 | EIGEN_STRONG_INLINE void _init1(const Scalar* data){
[build] | ^
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/PlainObjectBase.h:889:30: note: candidate function [with T = boost::pfr::detail::ubiq_lref_constructor]
[build] 889 | EIGEN_STRONG_INLINE void _init1(const Derived& other){
[build] | ^
[build] In file included from /home/chn/repo/nixos/packages/biu/test/yaml.cpp:1:
[build] In file included from /home/chn/repo/nixos/packages/biu/include/biu.hpp:8:
[build] In file included from /home/chn/repo/nixos/packages/biu/include/biu/eigen.tpp:3:
[build] In file included from /home/chn/repo/nixos/packages/biu/include/biu/eigen.hpp:4:
[build] In file included from /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/Dense:1:
[build] In file included from /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/Core:295:
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/Matrix.h:332:22: error: call to member function '_init1' is ambiguous
[build] 332 | Base::template _init1(x);
[build] | ~~~~~~~~~~~~~~~^~~~~~~~~
[build] /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include/c++/13.3.0/optional:214:8: note: in instantiation of function template specialization 'Eigen::Matrix::Matrix>' requested here
[build] 214 | : _M_value(std::forward<_Args>(__args)...)
[build] | ^
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/PlainObjectBase.h:839:30: note: candidate function [with T = boost::pfr::detail::ubiq_lref_base_asserting]
[build] 839 | EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if< (Base::SizeAtCompileTime!=1 || !internal::is_convertible::value)
[build] | ^
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/PlainObjectBase.h:875:30: note: candidate function [with T = boost::pfr::detail::ubiq_lref_base_asserting]
[build] 875 | EIGEN_STRONG_INLINE void _init1(const Scalar* data){
[build] | ^
[build] /nix/store/192041k004z7is2v7c29mgjq715m6w74-eigen-3.4.0/include/eigen3/Eigen/src/Core/PlainObjectBase.h:889:30: note: candidate function [with T = boost::pfr::detail::ubiq_lref_base_asserting]
[build] 889 | EIGEN_STRONG_INLINE void _init1(const Derived& other){
[build] | ^
[build] 2 errors generated.
```

Tested with C++ 23 standard, with both clang 18 and clang 19.

`Eigen::Matrix3d` means a matrix containing `double` elements with size of 3x3. Eigen is a popular math library.

It seems `pfr` trying to construct `std::optional` using `boost::pfr::detail::ubiq_lref_constructor`, then `optional` forwarded the construction to `Eigen::Matrix3d`.

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.