ProgramMax / max

max is a tool belt for C++
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Add a standard way to print messages/warnings/errors #110

Closed ProgramMax closed 5 years ago

ProgramMax commented 5 years ago

Is your feature request related to a problem? Please describe. The way a messages/warning/error is printed is different between different compilers. It would be nice within max and for users of max to be able to use these in a standard way.

Describe the solution you'd like MAX_INFORMATION(Some info here) MAX_WARNING(Some warning here) MAX_ERROR(Some error here)

Describe alternatives you've considered Could do a short form like MAX_INFO() and MAX_WARN(). But there isn't a 4-char ERROR that works nicely. ERR or ERRO or EROR or ERRR...they all feel wrong.

Additional context This would be useful for issue #109

ProgramMax commented 5 years ago

I don't think I'll be able to get all of messages, warning, and errors.

Clang supports a way to do all three. But GCC only handles messages and VC handles only messages and errors. I realized you could just use static_assert to get errors in GCC. But that also means we don't need a macro for it.

This leaves only messages fully supported and warnings only supported in Clang.

To be clear, there IS a way to print warnings in GCC. But it can't be made compiler-agnostic.

define MAX_STRINGIFY2(Message) #Message

define MAX_WARNING(Message) _Pragma(MAX_STRINGIFY2(GCC warning "Message here"))

The problem is GCC requires a single string inside the _Pragma. You can't combine multiple strings. Ideally, you would want something like:

define MAX_WARNING(Message) _Pragma("GCC warning" MAX_STRINGIFY2(Message))

Anyway, I'm changing this to only messages. And I'll cry a little bit because what I really wanted out of all this was a way to do warnings.

ProgramMax commented 5 years ago

An important clip from https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html "There is no way to combine an argument with surrounding text and stringify it all together."

It then goes on to talk about how adjacent string literals will be combined in the compiler phase, but not the preprocessor phase.