相关疑难解决方法(0)

gcc size_t and sizeof arithmetic conversion to int

I decided to test compile a project with -Wsign-conversion enabled, to see what warnings would come up, and came across something that doesn't seem right, where gcc behaves differently than clang. Can someone please tell me which is correct?

I have a function that takes a size_t param:

void func(size_t) {}
Run Code Online (Sandbox Code Playgroud)

some other struct

struct Test {};
Run Code Online (Sandbox Code Playgroud)

and calling code

int i = some_initialiser();
func(sizeof(Test) + static_cast<size_t>(i));
Run Code Online (Sandbox Code Playgroud)

So from my understanding, sizeof returns size_t, and arithmetic between two variables …

c++ gcc-warning implicit-conversion

3
推荐指数
1
解决办法
103
查看次数

标签 统计

c++ ×1

gcc-warning ×1

implicit-conversion ×1