Conversation
4130917 to
de28a0f
Compare
|
I think it's ready to merge. The change is not really deep, just add few |
|
I struggle with the gcc specific enabling and disabling of specific warnings, can we instead fix the code and have gcc not warn? |
Unfortunately, these
May be my experience with C is not enough to find a "good" example, but as far as I can say, the pattern to "unconst" unsafely (according to |
|
Probably @haesbaert or @Kensan have more knowledge (and a good opinion) about |
|
I finally found something which seems good enough (at least, for my perspective). I deleted A fix is needed for the virtio backend where we would like to set The only remaining |
|
Your MR reminds me of N2973 Qualifier-preserving standard library functions. You may find something that helps in the "Implementation" subsection. I've also found https://inbox.sourceware.org/libc-alpha/mvm5x8wpsmi.fsf@suse.de/T/. |
|
Thanks @MisterDA, I was able to remove few lines and propose something more clean than before (without repetition). I also applied |
|
A gently ping to @MisterDA to have a formal review (and if @Kensan or @haesbaert would like to participate). |
|
Just a note, in my experience |
This patch mainly try to lint our codebase with few warnings. It introduces also the usage of _Generic (C11) to be able to keep const qualifier between arguments and returned values (à la Rust).
|
For clarity, I rebased this PR to one commit, the diff is really small. I think it's ok to merge. |
|
C++ has /* const_cast(ptr) can only be used inside functions, on pointers */
#if (defined(__GNUC__) && __GNUC__ >= 14) || \
(defined(__clang_major__) && __clang_major__ >= 19)
#define const_cast(ptr) \
({ \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
(__typeof_unqual__(*(ptr)) *) (ptr); \
_Pragma("GCC diagnostic pop") \
})
#else
#define const_cast(ptr) (ptr)
#endif
int main(void) {
const int * const p0 = (void *)0;
int *p1 = const_cast(p0);
return 0;
} |
|
I think it's ok to merge now. |
| bool fail = false; | ||
| for (unsigned i = 0; i != virtio_manifest->entries; i++) { | ||
| if (!virtio_manifest->e[i].attached) { | ||
| if (i > 0 && !virtio_manifest->e[i].attached) { |
There was a problem hiding this comment.
I don't understand this change as part of this PR...
There was a problem hiding this comment.
wouldn't the same be to start from i = 1 in the for loop?
A comment why i=0 is special would be very welcome.
This patch mainly try to lint our codebase with few warnings. It introduces also the usage of _Generic (C11) to be able to keep const qualifier between arguments and returned values (à la Rust).