Skip to content

is there overdesign in friend template functions or a Bug in gcc? #11

@viboes

Description

@viboes

Wondering if the definition of friend template functions as in

template <class T>

doesn't implies a double definition.

clang 4.0.0 works ,but I'm getting in my implementation while compiling with gcc-6.1 the following

../include/experimental/fundamental/v3/bits/bit_pointer.hpp : dans l'instantiation de ‘class std::experimental::fundamental_v3::bit_pointer<short unsigned int>’ :
../include/experimental/fundamental/v3/bits/bit_iterator.hpp:51:79:   required from ‘class std::experimental::fundamental_v3::bit_iterator<std::_List_iterator<short unsigned int> >’
../example/bits/bit.cpp:104:94:   required from here
../include/experimental/fundamental/v3/bits/bit_pointer.hpp:187:40: erreur: redefinition of ‘template<class T> constexpr std::experimental::fundamental_v3::bit_pointer<WordType> std::experimental::fundamental_v3::operator+(typename std::experimental::fundamental_v3::bit_pointer<WordType>::difference_type, std::experimental::fundamental_v3::bit_pointer<WordType>)’
       friend constexpr bit_pointer<T> operator+(
                                        ^
../include/experimental/fundamental/v3/bits/bit_pointer.hpp:187:40: note: ‘template<class T> constexpr std::experimental::fundamental_v3::bit_pointer<WordType> std::experimental::fundamental_v3::operator+(typename std::experimental::fundamental_v3::bit_pointer<WordType>::difference_type, std::experimental::fundamental_v3::bit_pointer<WordType>)’ previously defined here
../include/experimental/fundamental/v3/bits/bit_pointer.hpp:198:15: erreur: redefinition of ‘template<class T, class U> constexpr typename std::common_type<typename std::experimental::fundamental_v3::bit_pointer<WordType>::difference_type, typename std::experimental::fundamental_v3::bit_pointer<U>::difference_type>::type std::experimental::fundamental_v3::operator-(std::experimental::fundamental_v3::bit_pointer<WordType>, std::experimental::fundamental_v3::bit_pointer<U>)’

Is this a bug in clang/gcc?

Why the following is not enough?

      friend constexpr bit_pointer operator+(
          difference_type n,
          bit_pointer x
      )

IMHO the constructor takes care already of the valid conversions, so even the mixed comparison should work directly with bit_pointer without needed bit_pointer<T> and bit_pointer<U>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions