0

I'm working on someone else's (C++20) codebase using Clion and the IDE is giving me this error (although the code itself is compiling and runnable using g++12):

In template: attempt to use a deleted function error occurred here in instantiation of function template specialization 'std::__detail::__variant::_Variant_storage<false, std::vector<int>, std::vector<std::basic_string<char>>>::_Variant_storage<0UL,
std::vector<int>>' requested here 

in instantiation of function template specialization 'std::__detail::__variant::_Variant_base<std::vector<int>, 
std::vector<std::basic_string<char>>>::_Variant_base<0UL, std::vector<int>>' requested here 

in instantiation of function template specialization 'std::variant<std::vector<int>, std::vector<std::basic_string<char>>>::variant<0UL, std::vector<int>, std::vector<int>, void>' requested here 

in instantiation of function template specialization 'std::variant<std::vector<int>,std::vector<std::basic_string<char>>>::variant<std::vector<int>, void, void, std::vector<int>, void>' requested here 

explicitly defaulted function was implicitly deleted here destructor of '_Variadic_union<std::vector<int>, 
std::vector<std::basic_string<char>>>' is implicitly deleted because variant field '_M_first' has a non-trivial destructor

I've tried to reproduce a minimal example that causes this; the situation is essentially the following:

#include <vector>
#include <string>
#include <variant>
using namespace std;

using IntTuples = vector<int>;
using StringTuples = vector<string>;
using ExtensionalTuples = variant<IntTuples, StringTuples>;

void do_something_with_extensional_tuples(ExtensionalTuples&& tuples) {
    // bla
}

int main() {
    IntTuples my_tuples{};
    do_something_with_extensional_tuples(move(my_tuples));
}

I thought that this should work, similar things seem to have worked in other places. So can anyone help me understand the error? Is it to do with a discrepancy between C++20 and C++17?

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
M. McIlree
  • 109
  • 3
  • Sounds like an IDE bug, unsure what we can do. – HolyBlackCat Oct 11 '22 at 11:01
  • Intellisence is never perfect – Guillaume Racicot Oct 11 '22 at 11:03
  • I mostly just want to check if it's definitely something that ought to work? Providing it's just an IDE bug that's fine. – M. McIlree Oct 11 '22 at 11:06
  • 1
    Neither Clion, nor any other IDE, are capable of producing any error messages. This is because IDEs are not C++ compilers, and only C++ compilers produce C++ error messages. If your question is about an error message from a particular C++ compiler, when a different C++ compiler, g++ 12, does not produce the error message, then that's fine, but you need to figure out exactly which compiler you are using. But it's probably a moot point, because if there's a compiler bug, then there is a compiler bug. The End. – Sam Varshavchik Oct 11 '22 at 11:11
  • @M.McIlree Try pasting your example into code explorer and try different compilers in their most recent version. – bitmask Oct 11 '22 at 11:11
  • 1
    @SamVarshavchik Unsure what your point is. Code completion engines (IntelliSense, Clangd, and whatever CLion uses) do produce error messages without running the compiler directly. – HolyBlackCat Oct 11 '22 at 11:20
  • Yeah I think it must be a problem with Clangd used by Clion. None of the compilers C++17 onwards in code explorer throw up any issues with it. I've not written C++ in a while so wasn't ruling out the possibility of it being me doing something wrong, but looks like I can safely ignore it! – M. McIlree Oct 11 '22 at 11:23
  • I've never seen Clangd disagree with Clang. I would figure out what version of Clangd they use, then try the respective Clang. Assuming the Clangd is configured with `compile_commands.json`, you can grab the command for the offending source file from the json, and run it (with `-fsyntax-only`) with Clang. – HolyBlackCat Oct 11 '22 at 11:33

0 Answers0