Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22122

compiler warning: left shift of negative value

$
0
0

I think GCC is wrongfully producing a [-Wshift-negative-value] warning.

I have a function that should produce a suffix mask of a certain length provided by its single input argument:

#include <stdint.h>

uint16_t get_suffix_mask_sht(uint8_t shift) {
    return (~(~((uint16_t) 0) << shift));
}

I have tried to compile this function with the following compiler options on different versions of gcc

-Werror -Wextra

This warning also occurs if I change the output from uint16_t to uint8_t. Bigger output types, i.e. uint32_t don't produce this warning.

I am using an older version of GCC: 7.4. But I have tried this out on godbolt using the latest GCC 9.x versions and they all produce the same warning. Clang versions however do not produce this error.


Viewing all articles
Browse latest Browse all 22122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>