-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Compilation error using "template <class T>" (prototypes generated incorrectly) [imported] #472
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
Comments
Can we promote this? Under version 1.5.8 of the IDE:
Gives error message:
The code generated by the IDE and sent to the compiler is:
Clearly the function-prototype generation is not recognizing this part:
... as being part of a function declaration. Surely that is easy to fix? |
Seems this would need to be fixed in these regexes: Not sure if we'll actually make things better here. We should really make this preprocessing stuff deprecated... |
I don't particularly mind that (except it would take a while to take effect). The preprocessing stuff would be OK, if it worked consistently, but it doesn't. And then you have to have function prototypes sometimes which confuses people as to why you sometimes need them and sometimes not. Here's another example, which doesn't use templates:
With the function prototype commented out you get the error:
The other side-effect is that often (in these cases) the wrong line gets highlighted by the IDE because the "real" problem is in the hidden prototype line which has been generated, and which the user doesn't see. It's not that hard to teach people to use prototypes, and indeed if you follow a simple rule they aren't usually necessary: Declare functions before you call them. So, if you put setup() and loop() last, and the things they call ahead of them (earlier in the source), everything works without prototypes anyway. |
Please checkout this thread [1] on devs mailing list and try one of the linked IDEs. It should fix almost all the problems reported in this issue. Typedefs are still incorrectly handled so @nickgammon example still won't work |
With this latest build https://groups.google.com/a/arduino.cc/d/msg/developers/4X2T3rCxXWM/WbQ2_dGzuhsJ even typedefs will work fine |
Fixed by #3779 |
Fix sending buffer in MySigning.cpp
I am using 1.6.8. I got this error: 'T' does not name a type. I don't see it fixed yet. Let me know if other version fixes this. |
@danlsk Compiles fine: // generic minimum
template <typename T> T minimum (T a, T b)
{
if (a < b)
return a;
return b;
} // end of minimum
void setup ()
{
int foo = minimum (6, 7);
}
void loop () { } |
|
Alright, I just figured out that it cannot break into 2 lines and must be on a single line.
But this one below works in 2 lines:
|
Yeah, the class function works on multiple lines as the IDE does not generate a prototype for it. Only file scoped functions are generated. IMO the multi line error should be fixed as templates can become very involved and a single line detracts from readability dramatically. Especially now that C++11 has been enabled, templates are a staple diet of the language and are more prevalent that ever (standard template lib for one). At least there is a workaround for now. |
This arduino/arduino-builder#182 PR should solve the multiline problem once for all , but the code is horribly convoluted and needs a big cleanup before merging. Anyway, if you could test it and report any bug you may encounter, it would be great! |
Will do, I can spend a little time trying to break it for you :) |
@Chris--A , |
just got home from work, will give it a spin shortly. |
Unfortunately there was no luck with the new code, test results here: arduino/arduino-builder#182 (comment) |
This is Issue 472 moved from a Google Code project.
Added by 2011-02-06T15:31:57.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Defect, Priority-Medium, Component-IDE, Component-PreProcessor
Original description
I found an error using the last revision of Arduino IDE (0022).
This code doesn't compile correctly:
The IDE returns this error:
error: expected ',' or '...' before '&' token
error: ISO C++ forbids declaration of 'T' with no type
error: 'T' has not been declared
Using version 0021 it works fine.
The text was updated successfully, but these errors were encountered: