Consider the following program:
struct uint1 {
unsigned x;
uint1(unsigned x_) : x(x_) { }
};
struct foo { uint1 a; };
foo f(int v) {
return {v};
}
struct bar { unsigned a; };
bar g(int v) {
return {v};
}
Now, where do we have narrowing conversions here?
| Compiler | version | narrowing conversion in f()? |
narrowing conversion in g()? |
|---|---|---|---|
| GCC | 11.2 | No | Yes |
| clang | 13.0 | No | Yes |
| MSVC | 19.4 | Yes | Yes |
Which is right? Naively, it seems to me there's a narrowing conversion in both functions.
See it all on GodBolt.
Note: C++17 in case it matters.