Hello!
This fixes following clang warning: ``` stash.c:92:6: warning: passing 'typeof (*(&type)) *' (aka 'volatile unsigned long *') to parameter of type 'gsize *' (aka 'unsigned long *') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] if (g_once_init_enter(&type)) ^~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/glib-2.0/glib/gthread.h:260:7: note: expanded from macro 'g_once_init_enter' (!g_atomic_pointer_get (location) && \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/glib-2.0/glib/gatomic.h:117:38: note: expanded from macro 'g_atomic_pointer_get' __atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \ ^~~~~~~~~~~~~~~~~ 1 warning generated. ``` Thanks! You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/2907
-- Commit Summary --
* <a href="https://github.com/geany/geany/pull/2907/commits/4b6c377b62f05a1068446f998077576d99d99e6d">Don't use volatile</a>
-- File Changes --
M src/stash.c (2)
-- Patch Links --
https://github.com/geany/geany/pull/2907.patch https://github.com/geany/geany/pull/2907.diff
You need to find what version of glib the volatile was removed, if it was waaaaay in the past ok, otherwise it might need a guard.
[Glib docs](https://github.com/geany/geany/pull/2907) say: "While location has a volatile qualifier, this is a historical artifact and the pointer passed to it should not be volatile."
Here's glib maintainer asking not to use `volatile`: https://discourse.gnome.org/t/should-the-g-once-init-enter-argument-be-marke... (The link from his comment has moved to http://c.isvolatileusefulwiththreads.com/)
@rootkea I'm not asking if the volatile is needed with current Glib, I know volatile is useless between threads.
As you said the volatile is still in the function definition in recentish Glib versions (2.64 from Ubuntu LTS for eg) but its gone from the docs for Glib 2.70, don't know about the code.
What I'm asking is will removing it on our variable make compilers complain the opposite way because the volatile is still on the function prototype? I know in C++ its UB to pass a non-volatile to a volatile, but C may be ok.
Ah, as I said - on latest main branch [g_once_init_enter](https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gthread.c#L699) still has arg qualified by `volatile` qualifier right after asking not to use `volatile`.
The `volatile` qualifier has been there on the function prototype since the very beginning of `g_once_init_enter` (as per git blame 2007) and has never been removed.
And I don't see a warning on this PR with clang version 12.0.0-3ubuntu1~21.04.2.
Well I was more worried about gcc 7 than clang 12 but I see Travis is using gcc 7.5 so probably ok.
Ah, as I said - on latest main branch g_once_init_enter still has arg qualified by volatile qualifier right after asking not to use volatile.
Ahh well, who knows what they are thinking, but anyway as my edit said it should be fine to pass a non-volatile to a volatile. And as I noted below, its a macro, not a real function, so parameter types are not checked.
(but now I'm puzzled why this warning then? Maybe I'm missing something)
Well, all the "functions" are actually macros (hisss booo) according to the error messages in the OP, until the _atomic load() function, so the type from the user code gets passed through to that function which does not have "volatile" on its prototype.
Merged #2907 into master.
github-comments@lists.geany.org