Skip to main content
HTD
Senior II
December 20, 2022
Question

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

  • December 20, 2022
  • 0 replies
  • 658 views

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()".

This topic has been closed for replies.