vendredi 22 janvier 2021

constant expression evaluates to -1 which cannot be narrowed to type 'char' [-Wc++11-narrowing] error

I am working with old code and I got an error at every -1 when compiling using newer C++ standard.

constant expression evaluates to -1 which cannot be narrowed to type 'char' [-Wc++11-narrowing]

Here is the snippet code

typedef struct {
    //short     len;
    //unsigned short cw;
    char        x, y, v, w;
} testStruct;

const testStruct testArr[] = {
    {   1,  -1,   0,   0},
    {  -1,   1,   0,   0},
    {   0,   0,  -1,   1},
    {   0,   1,  -1,   0},
    {   0,  -1,   1,   0},
    {   0,   0,   1,  -1},
    {   1,   1,   0,   0},
    {   0,   0,  -1,  -1},
    {  -1,  -1,   0,   0},
    {   0,  -1,  -1,   0},
    {   1,   0,  -1,   0},
    {   0,   1,   0,  -1},
    {  -1,   0,   1,   0},
    {   0,   0,   1,   1},
    {   1,   0,   1,   0},
    {   0,  -1,   0,   1},
    {   0,   1,   1,   0},
    {   0,   1,   0,   1},
    {  -1,   0,  -1,   0},
    {   1,   0,   0,   1},
    {  -1,   0,   0,  -1},
    {   1,   0,   0,  -1},
    {  -1,   0,   0,   1},
    {   0,  -1,   0,  -1}
};

I've tried to change the code and bracket to parentheses following warning: narrowing conversion C++11 , but I still got the same error. Is there any solution without reverting back to old C++ standard?

Aucun commentaire:

Enregistrer un commentaire