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

            Bug ID: 65854
           Summary: [c++-concepts] Type constraint satisfaction error for
                    type aliases; regression from r211824
           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

The following test case demonstrates what I believe to be an error in type
constraint satisfaction involving type aliases.  I believe the code should be
rejected with the noted error.  I have an old gcc build (r211824) that does
reject it (though the 'typename' keyword in the concept definition must be
removed for the compiler to reject it for the correct reason).  gcc r222333
(incorrectly) accepts it.

The test case defines a binary type trait template class (BTT), an alias
template that references it (Alias), a concept (C) that specifies a type
constraint using the alias, and declares a template function (f) that requires
the concept for its template parameters.  The call to f<char,int>() should be
rejected due to a failure of the type constraint in C (BTT<char,int>::type
won't exist), but gcc r222333 fails to reject.

Changing the concept to bypass the template alias and require 'typename
BTT<T1,T2>::type' instead suffices for gcc r222333 to correctly reject the
code.

$ cat t.cpp
template<typename T1, typename T2>
struct BTT {};
template<typename T>
struct BTT<T,T> {
    using type = int;
};

template<typename T1, typename T2>
using Alias = typename BTT<T1, T2>::type;

template<typename T1, typename T2>
concept bool C() {
    return requires() {
               typename Alias<T1, T2>;
           };
}

template<typename T1, typename T2>
requires C<T1, T2>()
int f();

auto i = f<char, int>(); // error: cannot call function

$ svn info   # From my local svn gcc repo.
Path: .
URL: svn://gcc.gnu.org/svn/gcc/branches/c++-concepts
Repository Root: svn://gcc.gnu.org/svn/gcc
Repository UUID: 138bc75d-0d04-0410-961f-82ee72b054a4
Revision: 222333
Node Kind: directory
Schedule: normal
Last Changed Author: asutton
Last Changed Rev: 222332
Last Changed Date: 2015-04-22 12:08:55 -0400 (Wed, 22 Apr 2015)

$ g++ -c -std=c++1z t.cpp 
<no error>

# Using an older gcc r211824 build (and having removed the 'typename' keyword
# preceding Alias in the concept definition that this old build didn't allow),
# the code is rejected (though the error message is a little off).  (note
# that this old build required -std=c++1y to enable support for concepts).
$ g++ -c -std=c++1y t.cpp
t.cpp:22:23: error: no matching function for call to ‘f()’
 auto i = f<char, int>();
                       ^
t.cpp:20:5: note: candidate: template<class T1, class T2> int f()
 int f();
     ^
t.cpp:20:5: note:   template argument deduction/substitution failed:
t.cpp:20:5: note:   constraints not satisfied  [with T1 = char; T2 = int]
t.cpp:20:5: note:   failure in constraint ‘template<class T1, class T2>
constexpr bool C()’
t.cpp:20:5: note:     ‘BTT<char, int>::Alias’ does not name a valid type

Reply via email to