I have the following function (given example):
QByteArray DecompressBytes(const QByteArray& content){
do { return content; } while(content.size() != 0);
}
The last line was added for testing, replacing the macro used. Visual Studio does not see a problem with this code, but g ++ generates
warning: control reaches the end of the non-void function [-Wreturn-type]
Changing the last line to return content;cancels the warning.
My question is: why does the compiler behave this way and what should be the form of the code to avoid any warnings?
The last line was ASSERT_FAIL("must be unreachable", content)c ASSERT_FAIL, expanding into a template do { ... } while(false)with another macro replacing whileto disable non-bool expressions, so the resulting expression was like do { qt_assert_x("", "", 42); return content; } while(::helper::bool_verify(false));.
g++ 5.3.0, MinGW ( Qt).
: ( ), :
QByteArray DecompressBytes(const QByteArray& content){
QByteArray decompressed;
do { return content; } while(content.size() != 0);
}
QByteArray DecompressBytes2(const QByteArray& content){
do { return content; } while(content.size() != 0);
}
std::vector<char> DecompressBytes3(const std::vector<char>& content){
std::vector<char> decompressed;
do { return content; } while(content.size() != 0);
}
std::vector<char> DecompressBytes4(const std::vector<char>& content){
int decompressed;
do { return content; } while(content.size() != 0);
}
, .