Skip to content

Compiler error with c++ templates using teensy platform only #94

@ktgilliam

Description

@ktgilliam

I can compile this code using gcc or the native platform in platformio, but I am getting an error when I build for the Teensy4.1:

template <typename T>
inline T saturate(T val, T lower, T upper)
{
   T val1 = val > lower ? val : lower;
   T val2 = val1 < upper ? val1 : upper;
   return val2;
}

int main()
{
    double v = 1.234;
    saturate(v, 0.0, 90.0);
    return 0;
}

The error I get is:
src/exec/MainExec.cpp: In function 'int main()': src/exec/MainExec.cpp:12:26: error: no matching function for call to 'saturate(double&, float, float)' saturate(v, 0.0, 90.0);

Expected behavior: the compiler to make all three arguments doubles.

Is this a bug with the teensy platform or with the compiler?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions