Project

General

Profile

Actions

Bug #8652

closed

Tautological comparisons with ZPROP_INVAL

Added by Alan Somers almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
zfs - Zettabyte File System
Start date:
2017-09-12
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
needs-triage
Gerrit CR:

Description

Clang and GCC prefer to use unsigned ints to store enums. With Clang, that causes tautological comparison warnings when comparing a zfs_prop_t or zpool_prop_t variable to the macro ZPROP_INVAL. It's likely that error handling code is being silently removed as a result.

Here's an example when using Clang to build libzfs on FreeBSD:
/usr/home/alans/freebsd/head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_changelist.c:434:24: error: comparison of constant 1 with expression of type 'zfs_prop_t' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (clp
>cl_shareprop != ZPROP_INVAL &&
~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
Here's that same error, as shown by GCC 6:
/usr/home/alans/freebsd/head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_changelist.c:434:24: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (clp->cl_shareprop != ZPROP_INVAL &&

I can't reproduce this problem on Illumos simply because its compiler is too old. I think GCC added this warning in version 6. I'm not sure when Clang added this warning.

Actions

Also available in: Atom PDF