Skip to content

Build fails with -Wc++11-narrowing error due to invalid char initialization in scoring.cpp #11

@stevenweaver

Description

@stevenweaver

Attempting to build cawlign fails on modern compilers (e.g. Clang 20) with a narrowing conversion error:

/home/sweaver/cawlign/src/scoring.cpp:154:28: error: constant expression evaluates to -1 which cannot be narrowed to type 'char' [-Wc++11-narrowing]
154 | char allowed_aa [255] {-1};
| ^~
| static_cast( )

This is caused by initializing a char array with -1, which is not portable and disallowed in C++11 and later when char is unsigned.

Steps to Reproduce:

git clone https://github.com/your-org/cawlign.git
cd cawlign
cmake .
make

Environment:
• Clang 20
• C++11 or higher

Suggested Fix:
Replace the declaration:

char allowed_aa[255] {-1};

with:

signed char allowed_aa[255];
std::fill_n(allowed_aa, 255, -1);

Or, cast explicitly (not portable if char is unsigned):

char allowed_aa[255] = { static_cast(-1) };

Workaround:
Build with -Wno-c++11-narrowing:

cmake -DCMAKE_CXX_FLAGS="-Wno-c++11-narrowing" .

But a code fix is preferable for portability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions