bool to size_t warning

Jonny Grant
Fri Aug 9 20:32:00 GMT 2019

Looks like the bool can't be converted to size_t

Seems a shame it can't also convert to size_t

What is strange in the example below, is I change it only a single 
conversion, or as follows, it compiles ok, so there must still be a 

Is this an issue worth reporting as a PR?

size_t i = a;
i += b;

The C spec states *|true|*which expands to the integer 
constant*|1|*,*|false|*which expands to the integer constant*|0|*


boola = false;
boolb = true;
//size_t i = a;
size_t i = a + b;


#1 with x86-64 gcc (trunk)
<source>: In function 'int main()':

<source>:9:18: error: conversion to 'size_t' {aka 'long unsigned int'} 
from 'int' may change the sign of the result [-Werror=sign-conversion]

     9 |     size_t i = a + b;

       |                ~~^~~

cc1plus: some warnings being treated as errors

Compiler returned: 1

Please include my email in any replies
Thanks, Jonny

More information about the Gcc-help mailing list