After switching to F31 beta I came across a GCC warning that looks like it is useful, trying to warn about misguided uses of the G_CONST_RETURN macro from glib-2.0. However, it leaves me puzzled:
$ cat test.c #include "glib.h" G_CONST_RETURN char * f();
On F30:
~ gcc --version gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ gcc $(pkg-config -cflags glib-2.0) -c test.c
works fine. On F31 beta,
~ gcc --version gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ gcc $(pkg-config -cflags glib-2.0) -c test.c test.c:2:13: warning: const 2 | G_CONST_RETURN char * f(); | ^~~~~~~
emits a cryptic warning (and gets the positioning of the squiggly underline wrong).
On both F30 and F31, /usr/include/glib-2.0/glib/gmacros.h contains
/* Deprecated -- do not use. */ #ifndef G_DISABLE_DEPRECATED #ifdef G_DISABLE_CONST_RETURNS #define G_CONST_RETURN #else #define G_CONST_RETURN const #endif #endif
so I'm not sure what causes the warning to be emitted on F31 but not on F30.
(https://developer.gnome.org/glib/unstable/glib-Standard-Macros.html#G-CONST-RETURN:CAPS states: "The macro can be used in place of const for functions that return a value that should not be modified." So the intent of the warning appears to be to warn about uses of G_CONST_RETURN that don't make the return type const, but rather make the return type be e.g. pointer-to-const as in my example.)
On 25/09/2019 17:16, Stephan Bergmann wrote:
~ gcc $(pkg-config -cflags glib-2.0) -c test.c test.c:2:13: warning: const 2 | G_CONST_RETURN char * f(); | ^~~~~~~
emits a cryptic warning (and gets the positioning of the squiggly underline wrong).
On both F30 and F31, /usr/include/glib-2.0/glib/gmacros.h contains
/* Deprecated -- do not use. */ #ifndef G_DISABLE_DEPRECATED #ifdef G_DISABLE_CONST_RETURNS #define G_CONST_RETURN #else #define G_CONST_RETURN const #endif #endif
so I'm not sure what causes the warning to be emitted on F31 but not on F30.
So Clang gives it away:
test.c:2:1: warning: const [-W#pragma-messages] G_CONST_RETURN char * f(); ^ /usr/include/glib-2.0/glib/gmacros.h:913:30: note: expanded from macro 'G_CONST_RETURN' #define G_CONST_RETURN const GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const) ^ /usr/include/glib-2.0/glib/gversionmacros.h:387:49: note: expanded from macro 'GLIB_DEPRECATED_MACRO_IN_2_30_FOR' # define GLIB_DEPRECATED_MACRO_IN_2_30_FOR(f) GLIB_DEPRECATED_MACRO_FOR(f) ^ /usr/include/glib-2.0/glib/gmacros.h:990:38: note: expanded from macro 'GLIB_DEPRECATED_MACRO_FOR' #define GLIB_DEPRECATED_MACRO_FOR(f) _GLIB_GNUC_DO_PRAGMA(GCC warning #f) ^ /usr/include/glib-2.0/glib/gmacros.h:988:33: note: expanded from macro '_GLIB_GNUC_DO_PRAGMA' #define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x)) ^ <scratch space>:110:6: note: expanded from here GCC warning "const" ^ 1 warning generated.
(At least partly; /usr/include/glib-2.0/glib/gmacros.h has only 540 lines, there's no line 913; so whatever #line tricks get played there...)
On 25/09/2019 18:12, Stephan Bergmann wrote:
(At least partly; /usr/include/glib-2.0/glib/gmacros.h has only 540 lines, there's no line 913; so whatever #line tricks get played there...)
Ha, that part was easy: I looked at the file with Emacs, but had no Emacs installed on the F31 system, just a Flatpak version (which then of course shows /usr/include/... in the Flatpak runtime, but otherwise behaved inconspicuous enough to fool me into believing I was running the "real thing"). :)
But still, the GCC warning messages should be better...