Bug 67150

Summary: [c++-concepts] Expression constraint fails with dependent types used as a deduction constraint target
Product: gcc Reporter: Casey Carter <Casey>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: eric.niebler, jason, webrown.cpp
Priority: P3    
Version: c++-concepts   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 67491    

Description Casey Carter 2015-08-07 22:01:02 UTC
r226725 fails to compile this program:

#include <type_traits>

template <class From, class To>
concept bool ExplicitlyConvertible =
  requires (From&& val) {
    requires std::is_same<From,bool>::value;
    requires std::is_same<To,bool>::value;
    requires std::is_same<decltype(val),bool&&>::value;
    static_cast<bool>((bool&&)val); // Line 9
    static_cast<To>((From&&)val);   // Line 10
  };

template <class T>
concept bool Boolean =
  requires (const T& t) {
    { t } -> ExplicitlyConvertible<bool>;
  };

constexpr bool f(Boolean) { return true; } // Line 19
static_assert(f(true));                    // Line 20

with error:

~/concept-gcc-r226725/bin/g++ -std=gnu++1z foo.cpp -c
foo.cpp:20:21: error: cannot call function ‘constexpr bool f(auto:1) [with auto:1 = bool]’
 static_assert(f(true));                    // Line 20
                     ^
foo.cpp:19:16: note:   constraints not satisfied
 constexpr bool f(Boolean) { return true; } // Line 19
                ^
foo.cpp:19:16: note:   concept ‘Boolean<bool>’ was not satisfied

It does compile correctly if line 10 is commented out, demonstrating that the expression "static_cast<To>((From&&)val)" is causing the constraint dissatisfaction despite the fact that From is bool, To is bool, and "static_cast<bool>((bool&&)val)" is acceptable.
Comment 1 Casey Carter 2017-02-16 22:20:41 UTC
This fails to reproduce on both GCC 6.3 and trunk.