Skip to content

[BUG] Signed to unsigned conversion warnings in bounds checking. #799

Closed
@gregmarr

Description

@gregmarr

Describe the bug
warning: implicit conversion changes signedness: 'int' to 'size_type' (aka 'unsigned long')

To Reproduce
Steps to reproduce the behavior:

  1. Sample code - distilled down to minimal essentials please

https://cpp2.godbolt.org/z/Wh7jTczzh

main: () = {
    v: std::vector = ( 1, 2, 3, 4, 5 );
    v[6] = 0;
}

Can avoid the warning by using v[6u].

  1. Command lines including which C++ compiler you are using
    -std=c++23 -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value

  2. Expected result - what you expected to happen

Clean compile, and out of bounds access error when executed.

  1. Actual result/error
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:467:30: warning: implicit conversion changes signedness: 'int' to 'size_type' (aka 'unsigned long') [-Wsign-conversion]
  467 |     return CPP2_FORWARD(x) [ CPP2_FORWARD(arg) ];
      |            ~~~~~~~~~~~~~~~   ^~~~~~~~~~~~~~~~~
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:271:37: note: expanded from macro 'CPP2_FORWARD'
  271 | #define CPP2_FORWARD(x)             std::forward<decltype(x)>(x)
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
build/main.cpp:19:11: note: in instantiation of function template specialization 'cpp2::assert_in_bounds<std::vector<int>, int>' requested here
   19 |     cpp2::assert_in_bounds(std::move(v), 6) = 0;
      |           ^
1 warning generated.

Additional context
Investigating #798 File name and line number when the application terminates

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions