I need some help in understanding why my GCC didn't consider this an issue. I have a function that was constructing a path to a daemon program based on the location of the shared object file where this code is. Something similar to this:
namespace {
std::string ConstructPath()
{
int lastSlash(0);
std::string pathVar;
Dl_info dl_info;
memset(
if((dladdr((void*)ConstructPath,
}
pathVar = dl_info.dli_fname;
lastSlash = pathVar.find_last_of('/');
if(std::string::npos == lastSlash)
{
// no slashes given ... must be that *.so
// is in the current directory
pathVar = "mydaemond";
}
else
{
pathVar.erase(pathVar.begin() + (lastSlash + 1), pathVar.end());
pathVar.append("mydaemond");
}
// first check if we can find the daemon
{
// introducing sub-scope to ensure the file object is closed
std::ifstream test(pathVar.c_str());
if(!test.good())
{
throw std::runtime_error("cannot find mydaemond");
}
}
// *** the below statement wasn't there originally, the
// *** function simply exited after the forced-scope block above,
// *** however, the function *did* have the return type
return pathVar;
}
}
My comments above the final return statement illustrate what my question is about. Why wasn't this a problem? There was no return statement and yet, the code compiled fine. I'm using GCC 4.4.4 on CentOS 6.2. Is this just a problem with the 4.4.4 compiler that was fixed? I'm betting there's some subtlety in C++ here that I'm not yet aware of and I'd like to be schooled.