Closed DyXel closed 1 week ago
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
.
Thanks! Fixed... now the first case works as expected, and the second case gives the correct "not customized" message for filesystem::path
.
That said, I could see adding support for "anything you can stream with <<
by pushing it through a stringstream
" and I've added a code comment for that, but the naive overload creates ambiguities with other overloads so I think the right thing is to change those core to_string
overloads into a single function with if constexpr
alternatives (as @filipsajdak did with is
, thanks again Filip!) and then it should work fine... I just didn't have time to do that today.
Thanks. I think the crashes were related to the fact that auto to_string(...)
uses the old vararg stuff from C. So the compiler was right about warning for that.
For the std::filesystem::path
one, I was getting very frustrated because I thought that ought to work, and in fact, the documentation says that it has operator string_type()
, what is not obvious is the fact that string_type
is probably not the regular std::string
but std::wstring
on Windows, so yeah...
Describe the bug Title. This one has different effects on different compilers.
To Reproduce Steps to reproduce the behavior:
my_enum: @enum type = { foo; bar; }
aaa: () -> std::string = { a := my_enum::foo; return "(a)$"; }
bbb: () -> std::string = { p: std::filesystem::path = (); return "(p)$"; }
main: () = std::cout << aaa() << bbb();
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.
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'