[Bug c++/77811] New: [concepts] invalid redefinition error when declaring friend function

ryan.burn at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Sep 30 20:41:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77811

            Bug ID: 77811
           Summary: [concepts] invalid redefinition error when declaring
                    friend function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ryan.burn at gmail dot com
  Target Milestone: ---

The below code should be valid but gives this error when compiling with gcc
(7.0.0 201609)

prog.cc: In instantiation of 'struct B<int>':
prog.cc:22:20:   required from here
prog.cc:16:14: error: redefinition of 'template<class S> int f(const S&)'
   friend int f(const S& s) {

/////////////////////////////////////////////////////////////////////////
#include <type_traits>

template<class T>
struct A {
  template <class S>
    requires std::is_same<S, A>::value
  friend int f(const S& s) {
    return 0;
  }
};

template <class T>
struct B {
  template <class S>
    requires std::is_same<S, B>::value
  friend int f(const S& s) {
    return 1;
  }
};

int main() {
  A<int> a; B<int> b;
  int x = f(a);
  int y = f(b);
  return 0;
}
/////////////////////////////////////////////////////////////////////////


More information about the Gcc-bugs mailing list