Problem c10/utils/variant.h


Maybe I’m doing something wrong but I’ve got a problem with libtorch 1.4.0 (I’m using the pre-built binaries you can find at - Ubuntu 16.04 with gcc-5.4)
The code I’m trying to build is the following one

//Include standard libraries
#include <iostream>

//Define namespace data
//This can be included for example by another header file
namespace data

//Include torch library
#include <torch/torch.h>

int main(int argc, char* argv[])
  std::cout << torch::randn({3, 3}) << std::endl;
  return 0;

The CMakeLists.txt is

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

find_package(Torch REQUIRED)

add_executable(test_variant main.cpp)
target_link_libraries(test_variant "${TORCH_LIBRARIES}")
set_property(TARGET test_variant PROPERTY CXX_STANDARD 14)

I’ve added an empty “data” namespace to better explain the problem.
When I build the example I get a lot of errors like

~/test_variant/libtorch/include/c10/util/variant.h:2519:7: error: invalid use of ‘void’
       AUTO_RETURN(v && holds_alternative<I>(*v)

I’ve looked inside the file and it seems that the problem is the statement (line 1165 c10/utils/variant.h)

              data(lib::forward<V>(v)), in_place_index_t<I>{}))

Where “data” is incorrectly detected as the namespace I’ve added before the <torch/torch.h> inclusion.
I think it should refer to the “data” function which can be found in the same file at line 1743 (I tried to change its name and indeed the error is solved).
Could this be an issue or it’s something I’m doing wrong in my code?

Thank you very much for your help :slight_smile:

Thanks for the code snippet and debugging.
Could you additionally create an issue on GitHub to discuss this error?

Sure, I’ll do that

Thank you :slight_smile:

1 Like