https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114237
Bug ID: 114237
Summary: GCC emits no narrowing conversion warning when call is
made indirectly through std::invoke
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlame646 at gmail dot com
Target Milestone: ---
Gcc emits no narrowing conversion warning for the following program. Only msvc
emits the warning. https://godbolt.org/z/EPKv9fdWr
```
void expectsInt32(int32_t) {
/* … */
}
template<typename Func, typename Arg>
void call(Func func, Arg arg) {
std::invoke(func, arg); // arg is size_t, potentially causing narrowing
conversion
}
int main() {
size_t largeNumber = 4294967295; // Maximum value for uint32_t
call(expectsInt32, largeNumber); // Compiles without warning in GCC/Clang
with -Wconversion
return 0;
}
```
Even with -Wconversion and other flags as shown in the demo, no warning is
emitted by gcc and clang.