cancel
Showing results for 
Search instead for 
Did you mean: 

"Placement new" and "std::tuple" seem not to work in STM32CubeIDE projects despite C++17 language version used.

HTD
Senior III

Just try it:

std::tuple<int, int, int> testTuples() { return { 1, 2, 3 }; };
 
struct Test { int a = 0, b = 0, c = 0; };
 
int main()
{
    auto [a, b, c] = testTuples();
    void* mem = malloc(3 * sizeof(int));
    auto test = new(mem)Test;
}

The code above compiles in Visual Studio, does not compile in STM32CubeIDE.

Surprisingly "std::pair" works.

Though tuples are just some syntax sugar, no "placement new" is really annoying, because you either must manually re-initialize structs when needed, or allocate new memory, or use ugly deprecated hack with "memset()".

0 REPLIES 0