Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ktgilliam opened this issue Oct 17, 2022 · 4 comments · Fixed by GoobyCorp/platform-teensy#1
Closed

Comments

@ktgilliam
Copy link

ktgilliam commented Oct 17, 2022

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?

@PaulStoffregen
Copy link

I tried with Arduino IDE and it seems to work.

image

@PaulStoffregen
Copy link

However, it does fail if I use Teensy 3.2, where code is compiled with "-fsingle-precision-constant" option. This is the expected result with -fsingle-precision-constant.

Perhaps PlatformIO is incorrectly using -fsingle-precision-constant with Teensy 4.1? It is only supposed to be used with the older boards.

@blackketter
Copy link

Yup, it seems that -fsingle-precision-constant is used with all boards on platformio. I'll file a bug.

@valeros
Copy link
Member

valeros commented Oct 24, 2022

Thanks for reporting, should be fixed in the dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants