sharkdp / dbg-macro

A dbg(…) macro for C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better compile-time error messages

sharkdp opened this issue · comments

If a user calls dbg(x) with a value x of unsupported type X, the compiler prints a huge error message due to the missing operator<< overload:

error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘const X’)
   stream << value;
   ~~~~~~~^~~~~~~~

[… a lot of lines suggesting alternative overloads …]

If we could detect that dbg(…) is called with an unsupported type (*), we could potentially print a nicer error message.

(*) The check for whether or not a type is "supported" is actually a bit involved: it would require two stages: (1) check if X is one of the "natively" supported types like std::optional<T> or any container type (2) check if X has an operator<< overload for ostream.