You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] string interpolation of certain types warns about "non-portable usage of variadic functions" #1136
Command lines including which C++ compiler you are using
Clang 17: -std=c++20 -Wall -Wextra -pedantic -Werror
MSVC: /std:c++latest /MD /EHsc /experimental:module /W4 /WX
Expected result - what you expected to happen
I would expect these to compile on all compilers, they seem to work in GCC 14. But non-GCC compilers seem unhappy about it.
Actual result/error
On clang I get the following:
error: cannot pass object of non-trivial type 'typename std::remove_reference<my_enum &>::type' (aka 'my_enum') through variadic function; call will abort at runtime [-Wnon-pod-varargs]
63 | return { cpp2::to_string(cpp2::move(a)) };
| ^
1 error generated.
On MSVC I get roughly:
error C2220: the following warning is treated as an error
warning C4840: non-portable use of class 'std::filesystem::path' as an argument to a variadic function
note: 'std::filesystem::path::path' is non-trivial
note: see declaration of 'std::filesystem::path::path'
note: the constructor and destructor will not be called; a bitwise copy of the class will be passed as the argument
note: see declaration of 'std::filesystem::path'
So the @enum case seems to fail in clang (presumably because it defines a to_string member function?) and the std::filesystem::path case seems to fail on MSVC. This latter one I have no idea whats wrong. Additional context
For the @enum case, calling to_string directly seems to workaround the issue, although that mostly makes the string interpolation redundant.
Initially I thought about opening an issue for each case, but they seem very related. Also I think these have to do with the definition at cpp2util.h:1192.
Addendum: Clang always fails to compile this even if you don't turn up all the warnings. If you instead use -Wno-non-pod-varargs, it compiles, but once you execute the program it says: Illegal instruction.
Activity
DyXel commentedon Jun 22, 2024
Addendum: Clang always fails to compile this even if you don't turn up all the warnings. If you instead use
-Wno-non-pod-varargs, it compiles, but once you execute the program it says:Illegal instruction.