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

cleanup: clarify disabling of static assert checks #2451

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

nurupo
Copy link
Member

@nurupo nurupo commented Dec 4, 2023

Since we have now switched to C11 for all compilers but MSVC.

(tox-bootstrapd is Unix-only while MSVC is Windows-only, so MSVC using C99 is not an issue as it never builds tox-bootstrapd).


This change is Reviewable

@nurupo nurupo force-pushed the bootstrapd-static-assert branch 5 times, most recently from dcd1da5 to 26e1bea Compare December 5, 2023 00:05
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (65b3375) 74.39% compared to head (63fb294) 74.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2451      +/-   ##
==========================================
+ Coverage   74.39%   74.41%   +0.02%     
==========================================
  Files          87       87              
  Lines       26264    26264              
==========================================
+ Hits        19539    19545       +6     
+ Misses       6725     6719       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nurupo nurupo force-pushed the bootstrapd-static-assert branch from 26e1bea to 6ed61e6 Compare December 5, 2023 00:14
@nurupo
Copy link
Member Author

nurupo commented Dec 5, 2023

Those clang-tidy checks failing seem like false positives, because const int can't be used in static_assert() in C. clang-tidy is probably thinking of C++.

Anyway, changing this turned out to be rather annoying:

  1. cont int is not a constant expression in C and doesn't work with static_assert():

    error: static_assert expression is not an integral constant expression
    
  2. enum {foo = a, bar = b} doesn't work because we use the enums in a comparison:

    ./other/bootstrap_daemon/src/tox-bootstrapd.c:491:70: error: enumerated and non-enumerated type in conditional expression [-Werror=extra]
      491 |                     limit.rlim_cur = limit.rlim_max > RLIM_SUGGESTED ? RLIM_SUGGESTED : limit.rlim_max;
          |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  3. define it is then.


The whole point of the assert is to hint to the reader that the rest of the code was written under the assumption that rlim_suggested >= rlim_min so you should keep that property if you are going to modify the values of the constants. It's nice for it to get checked at compile-time in case someone edited without getting the hint.

@nurupo
Copy link
Member Author

nurupo commented Dec 5, 2023

Or should we just keep the code as it is with the clang-tidy checks disabled?

@nurupo nurupo marked this pull request as ready for review December 5, 2023 01:18
@nurupo nurupo requested a review from iphydf December 5, 2023 01:18
@nurupo nurupo added this to the v0.2.19 milestone Dec 5, 2023
@iphydf
Copy link
Member

iphydf commented Dec 5, 2023

Yes, disable the useless check.

Copy link
Member

@iphydf iphydf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Disable the checks with a brief explanation in the script.

@pull-request-attention pull-request-attention bot assigned nurupo and unassigned iphydf Dec 5, 2023
@nurupo nurupo force-pushed the bootstrapd-static-assert branch from 6ed61e6 to 43673d1 Compare December 5, 2023 11:53
@nurupo nurupo force-pushed the bootstrapd-static-assert branch from 43673d1 to 63fb294 Compare December 5, 2023 11:56
@nurupo nurupo requested a review from iphydf December 5, 2023 11:57
@nurupo nurupo changed the title refactor: use static_assert in tox-bootstrapd cleanup: clarify disabling of static assert checks Dec 5, 2023
@nurupo nurupo merged commit 63fb294 into TokTok:master Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants