How do you return an error that communicates "missing quote on line 42 character 200"? A much better solution is to use std::expect (or something home baked if not available) and make the error type something that holds an actual context. HRESULT is a remnant of the past, not something you should replicate in your own code if you have the choice.
> How do you return an error that communicates "missing quote on line 42 character 200"?
For that use case you gonna need some other piece of data besides the error code. Maybe another type like json_error_t in Jansson library. Or maybe a special strings, like the ones returned by sqlite3_errmsg() in SQLite library.
> not something you should replicate in your own code if you have the choice
I believe HRESULT, despite rather old, is still the best error handling strategy overall.
Language-specific solutions like std::expected don’t work because all complicated software is written in multiple programing languages. For example, the entire ML ecosystem uses Python. 32-bit integers and strings are as language agnostic as you can possibly get.
Enums don’t work because most non-trivial libraries have an unbounded number of possible error conditions. You made a parser library for some format, defined an enum containing all possible failures of the parser, but then a user tried to parse a file he doesn’t have read access to. The failures need to include disk I/O errors. Another user gonna parse their source file from a mounted network share, the failures returned from your parser now need to include TCP/IP errors.
Typically, you have a parser handle and can use that to query it about various aspects of its state. Here it would include line number, character offset, and byte offset. The type of error can be encoded in the error return value.
https://en.cppreference.com/w/cpp/utility/expected