class template 'new' breaks compile on 1.8.9

Issue:

Using ‘new’ to instantate a templated class results in a compiler error that the next line code was unexpected, as if a ‘;’ was missing.

Example:

templated class:

template<typename T> class Vec3
{
public:
    Vec3() : x(T(0)), y(T(0)), z(T(0)) {}
    ....

.ino usage causing error:

Vec3<unsigned char> *frameBuffer = new Vec3<unsigned char>[imageWidth * imageHeight];
for (uint32_t i = 0; i < imageWidth * imageHeight; ++i) frameBuffer[i] = Vec3<unsigned char>(255);

error:
‘for’ was unexpected.

Target:
Arduino Due

What was tried:

  • tried moving problem line to the .h (didn’t help)
  • stripped .ino down to just (didn’t help)
#include "geometry.h"
const uint32_t imageWidth = 4095;
const uint32_t imageHeight = 4095;
Vec3<unsigned char> *frameBuffer = new Vec3<unsigned char>[imageWidth * imageHeight];
for (uint32_t i = 0; i < imageWidth * imageHeight; ++i) frameBuffer[i] = Vec3<unsigned char>(255);

source:
Arduino code which does not compile:

Orignal code (exact same geometry.h and code using the library) which compiles fine with ‘c++’ on Linux or OSX:

A mistake:

for (uint32_t i = 0; i < imageWidth * imageHeight; ++i) frameBuffer[i] = Vec3<unsigned char>(255);

needs to go inside a function, so I stuck it in setup()

making progress - stay tuned

The following had to be changed:

  • all instances of stuff like "std::ostream" had to be commented out, since there's no file system on a Due and it's not supported.
  • all instanced of "std::min" or "std::max" had to be changed to just "min" or "max"

I realize now it's NEVER going to work on a Due with the "cow.h" model as it is 221k. Going to have to try with a much simpler model.