diff --git a/Exception.h b/Exception.h index 55e7883..51c7b8c 100644 --- a/Exception.h +++ b/Exception.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace coreutils { @@ -15,7 +16,20 @@ namespace coreutils { class Exception { public: - Exception(std::string text, std::string file = __FILE__, int line = __LINE__, int errorNumber = errno); + /// + /// file/line default to the caller's actual location. std::source_location::current() + /// is specifically defined by the standard to evaluate at the call site when used as a + /// default argument - unlike __FILE__/__LINE__ (preprocessor macros, which were used + /// here previously and always expanded to this header's own declaration line instead + /// of the real throw site, since macro expansion happens before the compiler even sees + /// "default argument" as a concept). Explicit callers (e.g. throw Exception(msg, + /// __FILE__, __LINE__)) are unaffected - the signature is unchanged. + /// + + Exception(std::string text, + std::string file = std::source_location::current().file_name(), + int line = std::source_location::current().line(), + int errorNumber = errno); std::string className; std::string file;