Name lookup for local class members inside templates

Consider the following code that mimics a constexpr lambda (proposed for C ++ 17, not available in C ++ 14).

 #include <iostream> template<int M, class Pred> constexpr auto fun(Pred pred) { return pred(1) <= M; } template<int M> struct C { template<int N> static constexpr auto pred(int x) noexcept { // simulate a constexpr lambda (not allowed in C++14) struct lambda { int n_, x_; constexpr auto operator()(int y) const noexcept { return this->n_ * this->x_ + y; // ^^^^ ^^^^ <---- here } }; return fun<M>(lambda{N, x}); } }; int main() { constexpr auto res = C<7>::template pred<2>(3); std::cout << res; // prints 1, since 2 * 3 + 1 <= 7; } 

Here lambda defined inside a member of the class template function template. Surprisingly, I have to this-> eliminate the lambda n_ and x_ member variables.

Live examples ( with this-> , without this-> )

I got the impression that this is only needed in dependent base classes, but the lambda class is just a local class, not a dependent base class.

Question : can someone point me to the appropriate standard for finding the name of local class members inside templates?

+6
source share
1 answer

Thanks to @dyp's comment, this is apparently a bug in Clang 3.5 / 3.6, which is fixed in Clang 3.7 tip trunk, g ++ 4.8.1 through the connector tip, compile this too.

+2
source

Source: https://habr.com/ru/post/989062/


All Articles