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

            Bug ID: 68781
           Summary: [concepts] requires in member function is not
                    unevaluated
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jarrydb at cse dot unsw.edu.au
  Target Milestone: ---

The following correct code fails to compile in r231384

template <typename T>
struct declval_helper
{
    static constexpr bool stop = false;
    static T value();
};

template <typename T>
T
declval()
{
    static_assert(declval_helper<T>::stop, "declval must not be used");
    return declval_helper<T>::value();
}

template <typename T>
struct A {
    static void foo(int);
};

void bar(int);

template <typename T>
    requires requires {
        bar(declval<T>());
    }
void foo(T t) {
}

class Foo {

    public:

    template <typename T>
        requires requires {
            bar(declval<T>());
        }
    void foo(T t) {
    }

};

void test() {
    Foo f;
    f.foo(5);

    foo(5);
}

with the error:

g++ -std=c++1z uneval.cpp -c
uneval.cpp: In instantiation of ‘T declval() [with T = int]’:
uneval.cpp:36:27:   required by substitution of ‘template<class T>  requires
predicate(requires{bar()((declval<T>)());}) void Foo::foo(T) [with T = int]’
uneval.cpp:45:12:   required from here
uneval.cpp:12:5: error: static assertion failed: declval must not be used
     static_assert(declval_helper<T>::stop, "declval must not be used");
     ^~~~~~~~~~~~~

Note that commenting out the line f.foo(5); works fine. So it is only a problem
for member functions.

Reply via email to