Quantcast
Viewing all articles
Browse latest Browse all 22052

GCC 8.3.1-3 on Red Hat fails on template class with static function using template parameter

When working with the devtoolset-8 on RedHat 7:

[eftlab@49af022e5a7c git]$ which g++
/opt/rh/devtoolset-8/root/usr/bin/g++
[eftlab@49af022e5a7c git]$ /opt/rh/devtoolset-8/root/usr/bin/g++ --version
g++ (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[eftlab@49af022e5a7c git]$ 

I've come accross a bug i'd like verified please:

#include <iostream>
#include <functional>

template<class ParentT>
class OpenSession {
public:
  std::function<void()> Run() {
    auto parent    = parent_;

    return [parent](std::function<void()> onSuccess, std::function<void()> onReject) mutable {
      std::function<void()> toRun = [](){};

      RunCallback(parent, toRun);
    };
  }

  void RunCallback(std::function<void()>& toRun) {}

private:
  ParentT* parent_ = nullptr;

  static void RunCallback(ParentT* parent, std::function<void()>& toRun) {}
};


int main(int, const char**) {
  return 0;
}

Compile this with g++ -std=c++17 test.cpp and I get the following error:

test.cpp: In lambda function:
test.cpp:13:32: error: 'this' was not captured for this lambda function
       RunCallback(parent, toRun);
                                ^

It looks to me like in a template class when a lambda capture is checking its arguments it doesn't know that there are references to the template functions in here which leaves me renaming my method as even changing to OpenSession<ParentT>::RunCallback(parent, toRun); the compiler still doesn't see the static function i'm really referring to. Has anybody got any wonderful compiler flags that might tweak this or any other suggestions? Thanks


Viewing all articles
Browse latest Browse all 22052

Trending Articles