-
Notifications
You must be signed in to change notification settings - Fork 23
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
Refactor to address compiler warnings #38
base: master
Are you sure you want to change the base?
Conversation
include/blisp.h
Outdated
#define UNUSED(x) (void)(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sidenote:
Root CMakeLists.txt requests C standard 23 via CMAKE_C_STANDARD
. C23 introduced official maybe_unused
attribute. Using latter might avoid clumsiness of ancient C helper construct and ease portability ("portable-across-compilers").
Ultimately, also matter of style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I had no idea this made it to C standard, assumed it was C++ only. Didn't notice this project asked for C23, a pleasant surprise. Updated to use the attribute instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, MSVC's C23 support is...what's the word I'm looking for...sparse. [[maybe_unused]]
is not implemented, yet.
From: https://en.cppreference.com/w/c/compiler_support/23
Compilation failure from GHA https://github.com/bdd/blisp/actions/runs/4845978847/jobs/8635225026
If C23 is already required (really?!?!) and you can propose a patch that
passes presubmit on all the platforms that matter (in the real world,
standards conformance is a spectrum, not an enum) I don't see the harm in
using [[maybe_unused]] and friends.
The problem we (and every other project in the real world) have is that we
have to work on compilers that are actually provided and work on real
platforms. That may be GCC 13 on FreeBSD but GCC 11 on Linux and LLVM 12 on
MacOS (all numbers made up). To me, the standards enforced by presumit are
the actual floor of requirements, so if you propose a change that passes
presubmits and uses C23 features, I'm likely to approve it.
To the original patch, it's worth mentioning that -Wall is a moving
target. -Wall on FreeBSD may have different warnings that -Wall on Linux.
IME it's best to express the warnings you actually care about explicitly if
you don't have a large number of active developers on a large number of
platforms (and this project doesn't...)
…On Sun, Apr 30, 2023 at 4:25 AM schrob ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In include/blisp.h
<#38 (comment)>:
> \ No newline at end of file
+#define UNUSED(x) (void)(x)
Sidenote:
Root CMakeLists.txt requests C standard 23 via CMAKE_C_STANDARD. C23
introduced official maybe_unused attribute. Using latter might avoid
clumsiness of ancient C helper construct and ease portability
("portable-across-compilers").
Ultimately, also matter of style.
—
Reply to this email directly, view it on GitHub
<#38 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACCSD36O7JVLOCYDF67UEBLXDYV2NANCNFSM6AAAAAAXIFWAOY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
- Unused function warnings Move function definitions in include/blisp_util.h to lib/blisp_util.c. Defining them as static leads to internal linkage, accessible in that translation unit, hence the warning. Their references are to be handled in other translation units, so they shouldn't be static. - Unused function parameters Use C attribute `[[maybe_unused]]` (introduced in C23) to suppress unused parameter warnings. - `blisp_chip_xxxxx_get_eflash_loader` implementations accept clock type but don't use it. - `drain` function only has a body under macOS and FreeBSD with preprocessor predicates. - Enable compiler warnings Now that warnings are address enable them `-Wall -Wextra -Wpedantic` for the library and the tool targets. N.B. An equivalent of MSVC should be added to CMakeLists.txt, as these would only work when using GCC or Clang.
I don't represent official stance on this project, but speaking for my own
projects...
If I say that my project requires X and some compiler doesn't support X and
X isn't represented in the presubmit testing, then that's just another of
the infinite combinations of life that doesn't work and not a reason to use
X.
I'm also realistic and don't wait for every compiler to implement the
entirety of X because none of my projects use the WHOLE language/libraries.
In this case, an iddef to dumb code down for MSVC would be trivial, but
it's not a reason, IMO, to hold the rest of code back.
Even if [[foo]] isn't implemented, it was the clear intent of the ISO group
to ignore or warn against unknown foo decorators, so I'd hope this wouldn't
be a build error anyway... But MSVCs open contempt of C standards is
decades long and hard to overestimate so I wouldn't guess what it does.
MSVC has held the industry back for 20+ years. This would hardly be the
first project to just not care. It's an awful complier with a good
debugger.
I'll try to review the patch in full later tonight.
…On Sun, Apr 30, 2023, 3:06 PM Berk D. Demir ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In include/blisp.h
<#38 (comment)>:
> \ No newline at end of file
+#define UNUSED(x) (void)(x)
Well, MSVC's C23 support is...what's the word I'm looking for...sparse.
[[maybe_unused]] is not implemented, yet.
[image: image]
<https://user-images.githubusercontent.com/11135/235373879-6015224b-7fbd-4715-b222-f4b199d0c7e4.png>
From: https://en.cppreference.com/w/c/compiler_support/23
—
Reply to this email directly, view it on GitHub
<#38 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACCSD37QYI6XM7U532G36VTXD3A2ZANCNFSM6AAAAAAXIFWAOY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Oh. I see now there IS a failing presubmit on this. (Why doesn't the GH mailer make that more clear? Ugh!) That's both fortunate (it caught the issue) and unfortunate (it claims to require support for C23, but supports a compiiler that doesn't really support C23.). As [[maybe_unused]] was part of C++17, it would be pretty hamfisted if they special-cased in the C front-end. Can you please upgrade the requirement in workspaces/whatever.yaml to try to use the latest MSVC as it looks like it might be using a 2019 version Barring that, it looks like the solution may be to try something approximately like:
(Code is free-handed. Expect problems.) Please try to trigger on _MSC_VER since we're tip-toeing around broken MSVC and not WIN32; people use Clang, GCC, or other working compilers on Windows. SO has many hint, but many are based on C++ (wheere this has been required since C++17) or otherwise before C23. There are a few answers that consider it, though, such as https://stackoverflow.com/a/75965534 Sorry, but It's simply annoying that there are so many different ways to spell this, though most compilers have had some form of this for 10+ years in their C/C++ front-ends. This is why the C/C++ groups (finally) decided to unify some of this stuff very recently. |
Unused function warnings Move function definitions in include/blisp_util.h to lib/blisp_util.c. Defining them as static leads to internal linkage, accessible in that translation unit, hence the warning. Their references are to be handled in other translation units, so they shouldn't be static.
Unused function parameters Define a macro for void casting unused parameters as a portable-across-compilers way to suppress these warnings.
blisp_chip_xxxxx_get_eflash_loader
implementations accept clock type but don't use it.drain
function only has a body under macOS and FreeBSD with preprocessor predicates.Enable compiler warnings Now that warnings are address enable them
-Wall -Wextra -Wpedantic
for the library and the tool targets.N.B. An equivalent of MSVC should be added to CMakeLists.txt, as these would only work when using GCC or Clang.
Current warnings on
master
: