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

Build warnings -- cleanup fallthrough warnings #248

Open
4 tasks
henrygab opened this issue Aug 14, 2020 · 4 comments
Open
4 tasks

Build warnings -- cleanup fallthrough warnings #248

henrygab opened this issue Aug 14, 2020 · 4 comments

Comments

@henrygab
Copy link

Currently three files use the following to disable this warning on a couple functions:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
// ... code that generates warnings ...
#pragma GCC diagnostic pop

That was done as a temporary measure in #207 to allow finding/fixing other issues in the code exposed by compiling with -Wall.

Here's a list of correct ways to fix these implicit fallthrough warnings:

NOTE: The comment method is legacy and very fragile. See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78497

If code will be compiled by multiple compilers / versions, consider defining a macro such as ADAFRUIT_FALLTHROUGH, that conditionally defines to C++17, GCC, or CLANG as available.

@hathach
Copy link
Member

hathach commented Aug 24, 2020

there is no need for ADAFRUIT_FALLTHROUGH just either use attribute fallthru or [[fallthrough]]. We only need to fix current gcc and worry about other compiler later on when needed.

@hathach
Copy link
Member

hathach commented Aug 27, 2020

I really like attribute(( fallthrough )); It should be able to work with existing old & new code, just use it in another library, works like a charm

https://github.com/adafruit/Adafruit_SPIFlash/pull/70/files#diff-0d585c34005499efb9fdee8db227e2eaR111

@henrygab
Copy link
Author

I agree that is a preferred attribute. Now the difficulty is in verifying that the code is actually doing the "right thing" in each case, before using this attribute. Else, the attribute will hide a true bug from smart compiler warnings.

@hathach
Copy link
Member

hathach commented Aug 31, 2020

@henrygab yeah, but I don't think we could find anyone that could insert it into the "right place" any time soon :(. Let's leave it as it is for now :)

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

No branches or pull requests

3 participants
@hathach @henrygab and others