-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Hidden warning during compilation #1728
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
Agreed, this has annoyed me for a while too. It seems that the core is not warning-free, so perhaps that's why the flag was introduced, but then at the least it should only be applied to the core and not the sketch and libraries. Even better, we should make the core warning free and compile everything without -w. |
we (italian community) are working in this direction, warning-free for (warning: italian language ahead) 2013/12/10 Matthijs Kooijman notifications@github.com
|
This comment was marked as off-topic.
This comment was marked as off-topic.
Previously, pointer casting was used, but this resulted in strict-aliasing warnings: IPAddress.h: In member function ‘IPAddress::operator uint32_t() const’: IPAddress.h:46:61: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] operator uint32_t() const { return *((uint32_t*)_address); }; ^ IPAddress.h: In member function ‘bool IPAddress::operator==(const IPAddress&) const’: IPAddress.h:47:81: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; ^ IPAddress.h:47:114: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; Converting between unrelated types like this is commonly done using a union, which do not break the strict-aliasing rules. Using that union, inside IPAddress there is now an attribute _address.bytes for the raw byte arra, or _address.dword for the uint32_t version. Since we now have easy access to the uint32_t version, this also removes two memcpy invocations that can just become assignments. This patch does not change the generated code in any way, the compiler already optimized away the memcpy calls and the previous casts mean exactly the same. This is a different implementation of a part of arduino#1399 and it helps toward fixing arduino#1728.
In C++, true and false are language keywords, so there is no need to define them as macros. Including stdbool.h in C++ effectively changes nothing. In C, true, false and also the bool type are not available, but including stdbool.h will make them available. Using stdbool.h means that we get true, false and the bool type in whatever way the compiler thinks is best, which seems like a good idea to me. This also fixes the following compiler warnings if a .c file includes both stdbool.h and Arduino.h: warning: "true" redefined [enabled by default] #define true 0x1 warning: "false" redefined [enabled by default] #define false 0x0 This fixes arduino#1570 and helps toward fixing arduino#1728. This only changed the AVR core, the SAM core already doesn't define true and false (but doesn't include stdbool.h either).
peekNextDigit() returns an int, so it can return -1 in addition to all 256 possible bytes. By putting the result in a signe char, all bytes over 128 will be interpreted as "no bytes available". Furthermore, it seems that on SAM "char" is unsigned by default, causing the "if (c < 0)" line a bit further down to always be false. Using an int is more appropriate. A different fix for this issue was suggested in arduino#1399. This fix helps towards arduino#1728.
Now that #1877 is merged, most of the warnings in the core are fixed (except for some USB-related warnings), which brings us a step closer to allowing warnings to be enabled again. There still are plenty of warnings in the core libraries, I expect though. As to enabling warnings, on the mailing list it was discussed to make this optional, and probably have a few levels of warnings. By defaults, either no warnings, or only selected warnings in the user sketch are enabled. Advanced users can increase the warning level to enable all warnings and show them for libraries and the core as well. https://groups.google.com/a/arduino.cc/d/msg/developers/5iaId6nPzqA/ZLCPph6w0kgJ If we take an opt-in approach to warnings for the core and libraries, we could even start to implement this now, even when not all warnings in the core and core libraries have been fixed yet. |
I cannot stress this point enough. It is really important to put quality
Without higher quality, more structure and easier library/driver You have my vote for adding -Wall and -Wextra to the compiler options, Mikael On 04/29/2014 10:50 AM, Matthijs Kooijman wrote:
|
I get that the Arduino libraries are not yet warning free, and you don't want to show errors to users. But the -w means I can't even turn them on for myself with #pragma diagnostic. This is incredibly frustrating. It's been over a year. Perfect is the enemy of good - nobody seems to be implementing optional warnings. Just remove -w, so the warnings show up in verbose mode, and so that I can put #pragma GCC diagnostic error "-Wall" in my own code. |
There is no excuse for poor software quality. The compiler warnings should be set at the highest possible level so that all potential problems are exposed. And then they should be corrected. I cannot stress the importance of this. Please introduce -Wall and -Wextra and then do the work. Suppressing and ignoring warnings is a very bad and unprofessional practice. |
@tomfelker and @mikaelpatel your concerns are clear and understandable. However we must keep in mind that Arduino is also and especially a learning tool. A warning caused by the core or some library and not by a sketch may scare a student. |
@ffissore I do understand that this initially is a lot of work to clean up all the warnings that are in libraries right now but after that phase the overall code quality will be so much better. I also believe that this will help students. |
I completely understand that we don't want to have to explain why a particular type-punned pointer breaks strict anti-aliasing rules, or whatever, to newbies. I am not saying warnings should be visible by default. I just want, personally, to be able to see warnings in my own code, without having to locally build the Arduino IDE or install hacky wrappers around gcc (as StackOverflow suggests). And that's currently technically impossible because of -w. I think if you take that out, even if the output is still hidden, then it should be possible for me to just add pragmas to make warnings be errors in my own code, and set verbose mode on locally. |
The output is hidden if you keep verbose compilation output unchecked. Take a look at file > preferences. In order to enable all warnings you need neither to build the IDE nor to use hacky wrappers. Just edit file platform.txt and remove |
@tomfelker The latest addition to the options is -mcall-prologues which turns out to reduce foot print further. Cheers! |
Thanks, that's very helpful! Removing all references to -w in my platform.txt allowed my pragmas to work. And with verbose mode off in the preferences, as per default, it actually has no user-visible student-confusing effect. So I'd be in favor of it being the default, but at least knowing where to set it is good enough for now. |
I've added a new preference "show all compiler warnings" that turns warnings on |
* upstream/master: (239 commits) Fix for issue arduino#292 Windows: build_pull_request needed to be upgraded as well Update revisions.txt Windows: JRE is chosen at build time via WINDOWS_BUNDLED_JVM property Update Tone.cpp Update revisions.txt Block discovery threads until packages is not null, otherwise boards discovered during startup will miss model name Also SerialDiscovery was affected by bug found at 40535df. Fixes arduino#2892 NetworkDiscovery was silently failing because packages werenìt ready yet. Fixes arduino#2837 Better preference for setting warnings level. See arduino@61592d7#commitcomment-10668365 SAM boards stop compiling due to way of handling params with spaces on different OSs. Fixed Update Tone.cpp Restored error messages. Got rid of MessageSyphon as ther were losing some error messages. Fixes arduino#2737 Windows: added listComPorts test case New preference: enable all compiler warnings, off by default. Fixes arduino#1728 and arduino#2415. Also affects arduino#2634 and arduino#2207 build.xml: spreading failonerror on all exec tasks, it's better to crash early Lib/Board Manager CRC check is now case insensitive. Fixes arduino#2953 License fix to audio library License fix Library Manager: better error message ...
Except if you can hide it... Like in the case of the IDE itself. If the hardware/firmware had been as bad, this would never have taken off. Dont get me wrong, the achievement is great.. the quality is not. |
Previously, pointer casting was used, but this resulted in strict-aliasing warnings: IPAddress.h: In member function ‘IPAddress::operator uint32_t() const’: IPAddress.h:46:61: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] operator uint32_t() const { return *((uint32_t*)_address); }; ^ IPAddress.h: In member function ‘bool IPAddress::operator==(const IPAddress&) const’: IPAddress.h:47:81: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; ^ IPAddress.h:47:114: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; Converting between unrelated types like this is commonly done using a union, which do not break the strict-aliasing rules. Using that union, inside IPAddress there is now an attribute _address.bytes for the raw byte arra, or _address.dword for the uint32_t version. Since we now have easy access to the uint32_t version, this also removes two memcpy invocations that can just become assignments. This patch does not change the generated code in any way, the compiler already optimized away the memcpy calls and the previous casts mean exactly the same. This is a different implementation of a part of arduino#1399 and it helps toward fixing arduino#1728.
peekNextDigit() returns an int, so it can return -1 in addition to all 256 possible bytes. By putting the result in a signe char, all bytes over 128 will be interpreted as "no bytes available". Furthermore, it seems that on SAM "char" is unsigned by default, causing the "if (c < 0)" line a bit further down to always be false. Using an int is more appropriate. A different fix for this issue was suggested in arduino#1399. This fix helps towards arduino#1728.
in brach 1.5.x avr-gcc is called passing argument -w, that hide all warning.
This is very bad as wanings help to find error in the code, especially if it is written by someone new to coding and the magic of pointers.
please, at least give a flag in preferencies to remove the evil -w flag.
thank you
The text was updated successfully, but these errors were encountered: