Modify THROW macro to use a constexpr function for file name, instead of macro.
continuous-integration/drone/push Build is passing Details

This prevents potential warnings (such as clang-tidy's "cppcoreguidelines-pro-bounds-pointer-arithmetic") from showing up when using this macro.
This commit is contained in:
Deukhoofd 2020-10-09 13:48:21 +02:00
parent 5fcebd4d4d
commit edaa9f496d
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 11 additions and 2 deletions

View File

@ -140,12 +140,21 @@ namespace ArbUt {
};
}
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
static constexpr const char* file_name(const char* path) {
const char* file = path;
while (*path) {
if (*path++ == '/') {
file = path;
}
}
return file;
}
#define THROW(message) \
std::stringstream ___ss; \
___ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \
___ss << "[" << file_name(__FILE__) << ":" << __LINE__ << "] " << (message); \
throw ArbUt::Exception(___ss.str());
#define NOT_REACHABLE THROW("Not reachable");
#define NOT_IMPLEMENTED THROW("Not implemented");