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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
> This seems inconsistent, as member functions are normally expected to be 
> usable anywhere within the class definition.

IIUC associated constraints are part of the function signature and thus aren't
late parsed like the function body is, so later-declared members aren't
generally usable in a constraint.

Interestingly, if we add a dummy argument to 'check' then we accept the call
(and treat it as an ADL-enabled call to an unknown function template where
unqualified lookup found nothing):

struct A
{
  template<typename T> requires (check<T>(0))
  auto func(T) { }

  template<typename T>
  static consteval bool check(0) { return true; }
};

But if we then try to actually use func, its constraint will always fail due to
'check' not being visible at the point of use (since associated constraints
aren't late-parsed):

int main() {
  A a;
  a.func(0); // error: ‘check’ was not declared in this scope, and no
declarations were found by argument-dependent lookup at the point of
instantiation
}

This behavior (for the modified testcase) is correct AFAICT (Clang behaves the
same).

Reply via email to