boostorg / wave

Boost.org wave module
http://boost.org/libs/wave
21 stars 49 forks source link

Support C++20 feature testing #108

Open jefftrull opened 4 years ago

jefftrull commented 4 years ago

C++20 introduces a special predefined macro __has_cpp_attribute() along with a set of predefined language feature macros, all described here. I think that at minimum __has_cpp_attribute() should be defined in C++20 mode, even if it always evaluates to true.

What's less clear to me is whether, and how, the return values should be user-programmable (e.g. for emulating a specific compiler version).

hkaiser commented 4 years ago

I'm not sure if this is something to be supported by Wave. There are arguments both ways.

On one hand, the output Wave produces should be consumable by any other compiler. And that compiler should be able to handle the feature macros depending on its own implementations. For this it might be better to leave the feature macros that identify compiler (i.e. language) features alone and pass them through to the output untouched.

On the other hand, feature macros that are explicitly defined by the standard library or the compiler could be handled by Wave as any other macro, which would require for __has_cpp_attribute() to be recognized by Wave in order to properly resolve preprocessor conditional expressions.

In the end, in order to achieve accurate preprocessing, the process would have to be targetable to a particular platform and/or compiler (in the same way as necessary for code that is referring to predefined macros like __clang__ and similar). This would require to be able to predefine those language attribute-tokens (like carries_dependency) through the command line.

jefftrull commented 4 years ago

What if there was a separate mechanism, via an API on the Context object, for adding attributes? Something similar to add_macro_definition - a separate table for use by __has_cpp_attribute that would allow people to emulate specific compilers...