Closed Light-Wizzard closed 2 years ago
Wow, yes, it was a typo, thanks. Strange, I didn't get any warnings from the compiler or from the static analyzer.
I have no idea why it did not give an error, crazy I know, I was going line by line through the code and saw it, at first I was not sure, so I deleted it, ran the app, and found it gave a different result, it was ignoring the + line completely, I found that it optimized it out, and that is when I knew it was a typo the compiler should have caught, it knew it was dead code, but gave no warning at compile-time, a bug for sure, maybe it has been reported, did not look, but code checker gives a warning about it, but you have to enable a lot more checks to see that warning about unused code.
Flesh
I have no warnings in Clang Tidy, the most popular checked. Also two compilers (MSVC and GCC) doesn't say a word.
I use Qt Creator, stock install for Arch Linux Manjaro, it uses /usr/bin/cppcheck, but you need to enable more test, I do it under Tools -> Options -> Analyzer -> and check all of them for Cppcheck Tab, but I found this the old fashion way, I was looking at the code at GitHub and it just popped out as odd, at first I had no idea why it compiles, but plus + is a strange concept with the compiler, it just appends to the last command, and just ignores anything it cannot append to, strange behavior, but it is not a bug according to that feature, it does not care what you add something to, empty braces prove that, so it is just a strange thing you need to look out for, according to the standard, you can do this, and there might be a case for it, but I have no idea what that might be, but you can compile a program with a call to + as long as the syntac is correct, in this case it was, it will make a string, and put the content into that string, but it has no method to call it, so it ends up being an unused variable or dead code, but if you made a call inside that string call, it will get executed, thus it becomes part of the code, but still marked as unused, I doubled checked this and it is right, although very wrong at the same time.
I started programming in C back in the late 60s and early 70s, and remembered when C++ added the concept of Classes to the + operator, this gives you the ability to do stuff like {} + "This"; , but if {} is empty, it gets dropped, and why + "This"; works, it uses a macro to achieve this level of insanity, but that C++ for you.
Flesh
Not sure why this compiles since it creates two lines of code, when it should be one:
https://github.com/crow-translate/QOnlineTranslator/blob/master/src/qonlinetranslator.cpp#L1442
Thanks, Flesh