noexcept depending on method of member

479 views Asked by At

Related to this question, I want to specify my private section after my public interface.

template<class T, void (T::*f)()>
class B
{
public:
    void g(int y) noexcept(noexcept(x.*f()))
    {}
private:
    T& x;
};

But I get an error from Clang that x is an undeclared identifyer.

mm_test.cpp:14:34: error: use of undeclared identifier 'x'
    void g(int y) noexcept(noexcept(x.*f()))
                                    ^

It compiles just fine if the declaration of member x occurs before the declaration of g. Am I not supposed to be able to use a member variable in a noexcept operator earlier in the class definition than its declaration? If not, how could I achieve an equivalent noexcept specifier without moving the declaration of x ahead?

0

There are 0 answers