diff mbox series

[v3,02/10] libvhost-user: Replace typeof with __typeof__

Message ID 79297841f1aad83d85297afef99369004d9d19a4.1671628158.git.marcel@holtmann.org
State New
Headers show
Series Compiler warning fixes for libvhost-user,libvduse | expand

Commit Message

Marcel Holtmann Dec. 21, 2022, 1:10 p.m. UTC
Strictly speaking only -std=gnu99 support the usage of typeof and for
easier inclusion in external projects, it is better to use __typeof__.

  CC       libvhost-user.o
libvhost-user.c: In function ‘vu_log_queue_fill’:
libvhost-user.c:86:13: error: implicit declaration of function ‘typeof’ [-Werror=implicit-function-declaration]
   86 |             typeof(x) _min1 = (x);              \
      |             ^~~~~~

Changing these two users of typeof makes the compiler happy and no extra
flags or pragmas need to be provided.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 subprojects/libvhost-user/libvhost-user.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini Dec. 22, 2022, 8:16 a.m. UTC | #1
On 12/21/22 14:10, Marcel Holtmann wrote:
> Strictly speaking only -std=gnu99 support the usage of typeof and for
> easier inclusion in external projects, it is better to use __typeof__.
> 
>    CC       libvhost-user.o
> libvhost-user.c: In function ‘vu_log_queue_fill’:
> libvhost-user.c:86:13: error: implicit declaration of function ‘typeof’ [-Werror=implicit-function-declaration]
>     86 |             typeof(x) _min1 = (x);              \
>        |             ^~~~~~
> 
> Changing these two users of typeof makes the compiler happy and no extra
> flags or pragmas need to be provided.
> 
> Signed-off-by: Marcel Holtmann<marcel@holtmann.org>
> Reviewed-by: Philippe Mathieu-Daudé<philmd@linaro.org>

The build system uses "c_std=gnu99".  If you are extracting 
libvhost-user and not using its build files, you need to add --std=gnu99 
yourself when compiling.

If you really don't want to do that, as long as it's just a couple 
underscores that's fine I guess, but mixed declarations and code are 
going to reappear sooner or later.  Please add a patch like this:

diff --git a/subprojects/libvhost-user/meson.build 
b/subprojects/libvhost-user/meson.build
index 39825d9404ae..5deecbfe377d 100644
--- a/subprojects/libvhost-user/meson.build
+++ b/subprojects/libvhost-user/meson.build
@@ -1,6 +1,13 @@
  project('libvhost-user', 'c',
          license: 'GPL-2.0-or-later',
-        default_options: ['c_std=gnu99'])
+        default_options: ['warning_level=1', 'c_std=gnu99'])
+
+cc = meson.get_compiler('c')
+add_project_arguments(cc.get_supported_arguments(
+  '-Wsign-compare',
+  '-Wdeclaration-after-statement',
+  '-Wstrict-aliasing'),
+  native: false, language: 'c')

  threads = dependency('threads')
  glib = dependency('glib-2.0')


to avoid regressions, and likewise for libvduse.

Paolo
Marcel Holtmann Dec. 22, 2022, 8:37 p.m. UTC | #2
Hi Paolo,

>> Strictly speaking only -std=gnu99 support the usage of typeof and for
>> easier inclusion in external projects, it is better to use __typeof__.
>>   CC       libvhost-user.o
>> libvhost-user.c: In function ‘vu_log_queue_fill’:
>> libvhost-user.c:86:13: error: implicit declaration of function ‘typeof’ [-Werror=implicit-function-declaration]
>>    86 |             typeof(x) _min1 = (x);              \
>>       |             ^~~~~~
>> Changing these two users of typeof makes the compiler happy and no extra
>> flags or pragmas need to be provided.
>> Signed-off-by: Marcel Holtmann<marcel@holtmann.org>
>> Reviewed-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> 
> The build system uses "c_std=gnu99".  If you are extracting libvhost-user and not using its build files, you need to add --std=gnu99 yourself when compiling.
> 
> If you really don't want to do that, as long as it's just a couple underscores that's fine I guess, but mixed declarations and code are going to reappear sooner or later.  Please add a patch like this:
> 
> diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-user/meson.build
> index 39825d9404ae..5deecbfe377d 100644
> --- a/subprojects/libvhost-user/meson.build
> +++ b/subprojects/libvhost-user/meson.build
> @@ -1,6 +1,13 @@
> project('libvhost-user', 'c',
>         license: 'GPL-2.0-or-later',
> -        default_options: ['c_std=gnu99'])
> +        default_options: ['warning_level=1', 'c_std=gnu99'])
> +
> +cc = meson.get_compiler('c')
> +add_project_arguments(cc.get_supported_arguments(
> +  '-Wsign-compare',
> +  '-Wdeclaration-after-statement',
> +  '-Wstrict-aliasing'),
> +  native: false, language: 'c')

good idea. I included that in v4 patchset.

Regards

Marcel
diff mbox series

Patch

diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index b55b9e244d9a..67d75ece53b7 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -62,8 +62,8 @@ 
 #endif  /* !__GNUC__ */
 #ifndef MIN
 #define MIN(x, y) ({                            \
-            typeof(x) _min1 = (x);              \
-            typeof(y) _min2 = (y);              \
+            __typeof__(x) _min1 = (x);          \
+            __typeof__(y) _min2 = (y);          \
             (void) (&_min1 == &_min2);          \
             _min1 < _min2 ? _min1 : _min2; })
 #endif