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

            Bug ID: 81198
           Summary: [concepts] Same type constraints not enforced for
                    constrained-type-specifiers specified in trailing
                    return types of abbreviated functions
           Product: gcc
           Version: c++-concepts
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at honermann dot net
                CC: andrew.n.sutton at gmail dot com, asutton at gcc dot gnu.org
  Target Milestone: ---

The Concepts TS (N4641) states the following in 7.1.6.4 [dcl.spec.auto] p4
(this section is now 10.1.7.4 in the WP):

"A constrained-type-specifier C1 within the declared return type of an
abbreviated function template declaration does not designate a placeholder if
its introduced constraint-expression (7.1.6.4.2) is determined to be
equivalent, using the rules in 14.6.6.1 for comparing expressions, to the
introduced constraint-expression for a constrained-type-specifier C2 in the
parameter-declaration-clause of that function declaration. Instead, C1 is
replaced by the template parameter invented for C2 (8.3.5)."

Gcc implements this behaviour (with an exception reported in bug 81139) for
abbreviated functions that do not specify a trailing return type, but not for
those that do:

$ cat t.cpp
template<typename> concept bool C = true;
template<C> class ct {};
ct<C> af1(C) { return ct<int>{}; }
auto af2(C) -> ct<C> { return ct<int>{}; }
auto v1 = af1('c'); // template instantiation fails.
auto v2 = af2('c'); // template instantiation succeeds.

$ g++ --version
g++ (GCC) 7.1.0
...

$ g++ -c -fconcepts t.cpp
t.cpp: In instantiation of ‘ct<C> af1(auto:1) [with auto:1 = char]’:
t.cpp:5:18:   required from here
t.cpp:3:31: error: could not convert ‘ct<int>{}’ from ‘ct<int>’ to ‘ct<char>’
 ct<C> af1(C) { return ct<int>{}; }
                               ^

The expected behaviour is that both template instantiations fail.

Reply via email to