Skip to content

Implicit type conversion - compiler warnings [+suggestion] #542

@jaw

Description

@jaw

When compiling with -Wconversion and -Wsign-conversion, the generated code results in some worrisome warnings about type conversions.

The main culprit seems to be the size_type in LoanableCollection:

class LoanableCollection
{
public:

    using size_type = int32_t;

This is mixed with size_t in the generated code which is unsigned. ( https://en.cppreference.com/w/c/types/size_t.html )
Does LoanableCollection::size_type really have to be signed?

This warning goes away if one changes this to size_t.

Would it be possible to change this to simply size_t?

Examples in the generated code

length() being int32_t here but returned as size_t:

SWIGINTERN size_t eprosima_fastdds_dds_LoanableSequence_Sl_HelloWorld_Sc_std_false_type_Sg____len__(eprosima::fastdds::dds::LoanableSequence< HelloWorld,std::false_type > const *self){
        return self->length();
    }

Operator being fed i of type size_t:

SWIGINTERN HelloWorld const &eprosima_fastdds_dds_LoanableSequence_Sl_HelloWorld_Sc_std_false_type_Sg____getitem__(eprosima::fastdds::dds::LoanableSequence< HelloWorld,std::false_type > const *self,size_t i){
        return (*self)[i];
    }

Thanks!

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