Skip to content

Name lookup in operator's requires-clause causes constraint recursion #150376

@ckwastra

Description

@ckwastra

This issue was previously discussed here, but I couldn't find a dedicated issue to track it, so I decided to open this one. Feel free to close this if it turns out to be a duplicate. Test code:

namespace N {
struct S {};
} // namespace N
using namespace N;

template <class T>
void operator+(T t1, T t2)
  // Trailing requires-clause
  requires(!requires { t1 + t2; });
void test_operator_trailing() {
  // - GCC, MSVC: OK
  // - Clang: error: satisfaction of constraint
  //   '!requires { t1 + t2; }' depends on itself
  S{} + S{};
}

template <class T>
  // Leading requires-clause
  requires(!requires(T t1, T t2) { t1 - t2; })
void operator-(T, T);
void test_operator_leading() {
  // - GCC, MSVC: OK
  // - Clang: error: satisfaction of constraint
  //   '!requires (T t1, T t2) { t1 - t2; }' depends on itself
  S{} - S{};
}

template <class T>
void f(T t1, T t2)
  // Trailing requires-clause
  requires(!requires { f(t1, t2); });
void test_function_trailing() {
  // GCC, MSVC, Clang: OK
  f(S{}, S{});
}

template <class T>
  // Leading requires-clause
  requires(!requires(T t1, T t2) { g(t1, t2); })
void g(T, T) {}
void test_function_leading() {
  // GCC, MSVC, Clang: OK
  g(S{}, S{});
}

I'm not sure whether the position of the requires-clause (leading vs. trailing) is supposed to significantly affect behavior, though in the examples above, all three major compilers seem to treat them the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsdiverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions