[Bug c++/95132] Concept checked after auto return type deduction

ppalka at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Oct 25 19:27:19 GMT 2020


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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
   Target Milestone|---                         |10.3

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #2)
> (In reply to Francesco Biscani from comment #0)
> > This is problematic because it means that another concept that would check
> > whether or not bar() can be called with a specific argument type would fail
> > with a hard compile time error, instead of marking the concept as not
> > satisfied.
> 
> Would you have a concrete testcase for this behavior?

Ah, here's one:

$ cat testcase.C
template<typename T> struct A {
  static auto f() requires false { return T::fail; }
};

template<typename T>
constexpr int v = requires { A<T>::f(); };

static_assert(!v<int>);

$ g++ -std=c++20 testcase.C
testcase.C: In instantiation of ‘static auto A<T>::f() requires  false [with T
= int]’:
testcase.C:   required from ‘constexpr const int v<int>’
testcase.C:   required from here
testcase.C: error: ‘fail’ is not a member of ‘int’
    2 |   static auto f() requires false { return T::fail; }
      |                                              ^~~~


We wrongly issue a hard error for the reason you pointed out.


More information about the Gcc-bugs mailing list