-
Notifications
You must be signed in to change notification settings - Fork 141
C++ : updated kata to Clang8C++17 passed by function without body #820
Comments
Looks like the For "Last digit of a huge number", solution without body crashes in random tests (segfaults). |
But passes "TEST". |
I know, I'm just listing my observations. It seems to be caused by |
Not returning a value from a function is undefined behavior, which gives the compiler freedom to do anything, not necessarily to return an unspecified value, so, apparently, the function has been optimized to always return what is expected (and Clang is known for sophisticated optimization as in famous https://kristerw.blogspot.com/2017/09/why-undefined-behavior-may-call-never.html). So it's not like something is wrong with the framework. I'm not sure what can be done about it though... |
Amongst the kata I tried some pass and some rightly fail. |
Yeah, you usually don't have optimization flag on while testing/developing. Most languages on Codewars doesn't have optimization/production flag on. @g964 Why not just provide valid initial solution? #include <list>
using namespace std;
int last_digit(list<int> array) {
// Write your code here
return 0; // <- added
} This won't prevent users submitting by removing that line, but it should prevent accidental ones. |
I think a wrapper with noinline may work, like [[gnu::noinline]]
int last_digit_wrapper(list<int> array) {
return last_digit(array);
} It seems that it works even without noinline in this kata, but it's probably less reliable. |
Maybe those that fails have |
I didn't try any others kata of mine except the first I mentioned in my first post. https://www.codewars.com/kata/56c5847f27be2c3db20009c3/train/cpp rightly fails https://www.codewars.com/kata/534d2f5b5371ecf8d2000a08/train/cpp passes |
https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html |
@error256 Nice find! The kata fails with
I still think a valid initial solution returning the empty value should be provided though. So add |
Deployed the fix. |
@kazk
Could you have a look at: https://www.codewars.com/kata/566fc12495810954b1000030/discuss/cpp
post by @gkontadakis. Someone updated the kata to Clang8C++17.
I tried https://www.codewars.com/kata/5518a860a73e708c0a000027/train/cpp too with a function without body and this solution also passed.
Same with a few others I tried. All we get are "STDERR" but it get passed.
I don't understand what happens:-(
The text was updated successfully, but these errors were encountered: