Boost logo

Boost :

From: Hans Dembinski (hans.dembinski_at_[hidden])
Date: 2020-10-30 13:52:30


Dear John and the other gurus,

a strange bug was reported for Boost.Histogram. It is a difficult one for which I would like to ask for help. To me it looks like a bug in gcc.

Here is the issue:
https://github.com/boostorg/histogram/issues/290

And here is a link to reproduce it:
https://godbolt.org/z/oK4866

The following innocent code compiled with gcc-7.1 or newer with -std=c++17
```
#include <boost/type_traits/rank.hpp>
#include <boost/histogram/axis/traits.hpp>

int main() { return 0; }
```

produces this error message (excerpt):

```
cc1plus: error: return type specified for deduction guide
In file included from <source>:2:
/celibs/boost_1_74_0/boost/histogram/axis/traits.hpp:411:11: error: 'decl-specifier' in declaration of deduction guide
  411 | constexpr unsigned rank(const Axis& axis) {
      | ^~~~~~~~
/celibs/boost_1_74_0/boost/histogram/axis/traits.hpp:411:1: error: 'decl-specifier' in declaration of deduction guide
  411 | constexpr unsigned rank(const Axis& axis) {
      | ^~~~~~~~~
/celibs/boost_1_74_0/boost/histogram/axis/traits.hpp:411:11: error: 'unsigned' specified with 'rank<...auto...>'
  411 | constexpr unsigned rank(const Axis& axis) {
      | ^~~~~~~~
/celibs/boost_1_74_0/boost/histogram/axis/traits.hpp:411:20: error: deduction guide for 'boost::rank<T>' must have trailing return type
  411 | constexpr unsigned rank(const Axis& axis) {
      | ^~~~
In file included from <source>:1:
/celibs/boost_1_74_0/boost/type_traits/rank.hpp:82:27: note: 'template<class T> struct boost::rank' declared here
   82 | template <class T> struct rank : public integral_constant<std::size_t, (::boost::detail::rank_imp<T, 0>::value)>{};
      | ^~~~
```

gcc interprets my function called `rank` as a deduction guide for `boost::rank` in boost/type_traits/rank.hpp. It then continues to complain that this function does not look like a deduction guide. Well, it isn't one, duh. I can see nothing wrong with my code or the code in boost/type_traits, so my guess is a bug in gcc. If you all agree, I would report this. If this is really a bug in gcc, however, it exists since v7.1 all the way to gcc trunk.

In either case, it would be great if we could use a workaround in Boost until that problem is fixed. I found a workaround is to replace line 82 in boost/type_traits/rank.hpp with:

```
template <class T> using rank = integral_constant<std::size_t, (::boost::detail::rank_imp<T, 0>::value)>;
```

This avoids the issue because now the struct ``rank`` is gone and therefore gcc does not try to find a deduction guide for it. Is there a better solution?

Best regards,
Hans


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk