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

            Bug ID: 68093
           Summary: [concepts] friend function declarations that differ
                    only by constraints are rejected as redefinitions
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at honermann dot net
  Target Milestone: ---

I believe the following code is intended to be well-formed according to P0121r0
[1].  gcc trunk (r229299) currently rejects it.

$ cat t.cpp
struct S1 {};
struct S2 { using t1 = int; };
template<typename T>
concept bool Has_t1() {
    return requires () { typename T::t1; };
}
template<typename T>
struct TS {
    friend void f(TS) {}
    friend void f(TS) requires Has_t1<T>() {} // Unexpected error: redefinition
};
TS<S1> ts1;
TS<S2> ts2;
auto x = []{
             f(ts1);
             f(ts2);
         };

$ gcc --version
gcc (GCC) 6.0.0 20151025 (experimental)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc -c -std=c++1z t.cpp 
t.cpp: In instantiation of ‘struct TS<S1>’:
t.cpp:12:8:   required from here
t.cpp:10:17: error: redefinition of ‘void f(TS<S1>)’
     friend void f(TS) requires Has_t1<T>() {} // Unexpected error:
redefinition
                 ^
t.cpp:9:17: note: ‘void f(TS<S1>)’ previously defined here
     friend void f(TS) {}
                 ^
t.cpp: In instantiation of ‘struct TS<S2>’:
t.cpp:13:8:   required from here
t.cpp:10:17: error: redefinition of ‘void f(TS<S2>)’
     friend void f(TS) requires Has_t1<T>() {} // Unexpected error:
redefinition
                 ^
t.cpp:9:17: note: ‘void f(TS<S2>)’ previously defined here
     friend void f(TS) {}
                 ^

[1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0121r0.pdf

Reply via email to