Skip to content

Commit a21a206

Browse files
committed
[UCRT] Add workaround for va_arg warning about type promotion
1 parent faedd8f commit a21a206

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sdk/lib/ucrt/inc/corecrt_internal_stdio_output.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,33 @@ namespace __crt_stdio_output {
3030
// reads the next argument of type T from the varargs list and updates the
3131
// va_list, just like va_arg does. The 'peek' function returns the next argument
3232
// of type T, but does not modify the va_list.
33+
#if defined(__GNUC__) || defined(__clang__)
34+
template<typename T> struct _va_arg_promoted_tye { using type = T; };
35+
template<> struct _va_arg_promoted_tye<signed char> { using type = int; };
36+
template<> struct _va_arg_promoted_tye<unsigned char> { using type = int; };
37+
template<> struct _va_arg_promoted_tye<wchar_t> { using type = int; };
38+
template<> struct _va_arg_promoted_tye<short int> { using type = int; };
39+
template<> struct _va_arg_promoted_tye<short unsigned int> { using type = int; };
40+
#endif
41+
3342
template <typename T>
3443
T read_va_arg(va_list& arglist) throw()
3544
{
45+
#if defined(__GNUC__) || defined(__clang__)
46+
return (T)(va_arg(arglist, typename _va_arg_promoted_tye<T>::type));
47+
#else
3648
return va_arg(arglist, T);
49+
#endif
3750
}
3851

3952
template <typename T>
4053
T peek_va_arg(va_list arglist) throw()
4154
{
55+
#if defined(__GNUC__) || defined(__clang__)
56+
return (T)(va_arg(arglist, typename _va_arg_promoted_tye<T>::type));
57+
#else
4258
return va_arg(arglist, T);
59+
#endif
4360
}
4461

4562

0 commit comments

Comments
 (0)