Bug 65854 - [c++-concepts] Type constraint satisfaction error for type aliases; regression from r211591
Summary: [c++-concepts] Type constraint satisfaction error for type aliases; regressio...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: concepts
  Show dependency treegraph
 
Reported: 2015-04-23 03:19 UTC by Tom Honermann
Modified: 2017-05-15 04:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Honermann 2015-04-23 03:19:33 UTC
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
Comment 1 Tom Honermann 2015-04-23 18:05:04 UTC
A correction.  I've been reading the svn info details incorrectly.  The old gcc build I have that accepts this code is r211591, not r211824.  Updated the summary.
Comment 2 Andrew Sutton 2015-05-04 15:47:16 UTC
Confirmed. Parsing a type requirement that names an alias template was giving back a declaration, which wasn't being instantiated correctly. 

r222769 unwraps the type from the declaration and will correctly reject the test case.
Comment 3 Tom Honermann 2015-05-05 15:23:20 UTC
Thank you!  I confirmed that this is corrected with r222769.  Changing status to resolved/fixed.