One problem with defining macros that expand to _Pragma("clang attribute")` is that they don't nest very well:
// In some header... #define ASSUME_X_BEGIN _Pragma ("clang attribute push(__attribute__((x)), apply_to=variable)") #define ASSUME_X_END _Pragma ("clang attribute pop") #define ASSUME_Y_BEGIN _Pragma("clang attribute push(__attribute__((y)), apply_to=variable)") #define ASSUME_Y_END _Pragma("clang attribute pop") // in some source file... ASSUME_X_BEGIN // lots of code ASSUME_Y_BEGIN // some more code ASSUME_X_END // oops! Popped Y, but meant to pop X. // some other code ASSUME_Y_END // ditto
This patch adds a way to fix this by adding labels to push/pop directives. A clang attribute pops with a label will only pop a pushed group with that same label. Macro authors can then add a unique label to their BEGIN/END functions, which would cause the code above to work fine.
Thanks for taking a look!
Erik
The documentation reads like the label is optional, but the examples make it look required (because all examples have the label present). Can you clarify what happens when the label is omitted and keep an example that shows it?