c++ - Name lookup for local class members inside templates -
consider following code, simulates constexpr
lambda (proposed 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 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 function template member of class template. surprisingly, have this->
ambiguate lambda
member variables n_
, x_
.
live examples (with this->
, without this->
)
i under impression necessary in dependent base classes, lambda
class local class, not dependent base class.
question: can point me relevant standardese name lookup of local class members inside templates?
thanks comment of @dyp, appears bug in clang 3.5 / 3.6 is fixed in clang 3.7 tip of trunk. g++ 4.8.1 through tip of trunk compile correctly well.
Comments
Post a Comment