Bug 67150 - [c++-concepts] Expression constraint fails with dependent types used as a deduction constraint target
Summary: [c++-concepts] Expression constraint fails with dependent types used as a ded...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: c++-concepts
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: concepts
  Show dependency treegraph
 
Reported: 2015-08-07 22:01 UTC by Casey Carter
Modified: 2017-02-16 22:20 UTC (History)
3 users (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 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.