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

            Bug ID: 96439
           Summary: [concepts] nested requirement allows calling a method
                    of a local parameter
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: src at andyf dot de
  Target Milestone: ---

Hello,

the following code is accepted by GCC 10.2.0 and trunk (as of 20200802):

template<int N>
struct array {
    constexpr auto size() const { return N; }
};

template<typename T>
concept C2 = requires(T a) {
    requires a.size() > 2; // "a" is a local parameter and should be allowed
only a an unevaluated operand
};

static_assert(C2< array<5> >);

My reading of [expr.prim.req.nested] p2 is, that is should be ill-formed, "a"
is a local parameter. The following code is (correctly in my opinion) rejected
by GCC:

template<typename T>
constexpr bool Fun(T& t)
{
    return true;
}

template<typename T>
concept C1 = requires(T a) {
    requires true == Func(a);
};

static_assert(C1<int>);


It looks to me, that in the case of calling a member function on a local
parameter the check is missing. Clang rejects both examples. MSVC 19.24 shows
the same behavior as GCC, so I might be misreading something.

Here is a godbolt link: https://godbolt.org/z/TeTdoK



Cheers,

   Andreas

Reply via email to