0

Rad Studio Rio 10.3.1, CLANG.

The simple code throws an exception in the assignment operator (y=x): 'std@bad_alloc'

typedef std::variant< std::string, int> MVariant;
MVariant x=10;
MVariant y;
y=x;

I cannot see the reason. What am I missing?

kokokok
  • 1,030
  • 1
  • 9
  • 26
  • It might sound silly, but can you extract a [mcve]? Also, tag this with "c++". That said, try to throw the code into https://gcc.godbolt.org/, to find out whether it's your compiler or your code. – Ulrich Eckhardt Jul 04 '19 at 16:43
  • I wrote the minimal reproducible example. It is the above. Just create a new project, a console or Form app and write the above C++ code. It is all. In the past, for other questions I used C++ tag but C++ users complained because it seems a problem related with the CLANG implementation for Builder C++, not for C++ in general. – kokokok Jul 05 '19 at 07:42
  • @UlrichEckhardt `std::variant` is new in C++17, but I can't get the code shown to compile on multiple online compiler sites, including gcc.godbolt.org and ideone.com. I guess they don't support C++17 yet? – Remy Lebeau Jul 05 '19 at 18:14
  • @kokokok offhand, the code looks fine, so it is likely a glitch in the implementation. C++17 support is a new feature in RAD Studio 10.3, so it likely has some bugs. [File a bug report with Embarcadero](https://quality.embarcadero.com). – Remy Lebeau Jul 05 '19 at 18:15

1 Answers1

0

I think that the problem is not in Rad Studio itself. It is about CLANG. This is known bug 33222 that seems to only affect libstdc++'s std::variant (and other constructs using the same combination). The problem is related to friend function to templates.

The variant from libc++ doesn't seem to use the technique of friends that libstdc++ used.

See get<string> for variants fail under clang++ but not g++

kokokok
  • 1,030
  • 1
  • 9
  • 26