nemequ / hedley

A C/C++ header to help move #ifdefs out of your code
https://nemequ.github.io/hedley/
Creative Commons Zero v1.0 Universal
774 stars 51 forks source link

IAR comiler for ARM errornously reports __has_attribute(nonnull) true #46

Closed badbadc0ffee closed 3 years ago

badbadc0ffee commented 3 years ago

The IAR compiler appears to by lying about attribute support:

__has_attribute(nonnull), __has_attribute(const) and __has_attribute(pure) are falsely reporting existing compiler support for these attributes (which leads to warnings when the resulting code is compiled).

Warning[Pa167]: the "__nonnull__" attribute is not supported

I'd suggest to suppress the attribute usage when using the IAR compiler for these attributes like so:

    #if defined(JSON_HEDLEY_NON_NULL)
    #undef JSON_HEDLEY_NON_NULL
    #endif
    #if \
        !defined(JSON_HEDLEY_IAR_VERSION) && \
        JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
        JSON_HEDLEY_GCC_VERSION_CHECK(...) || \
       ...
    #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
    #else
    #define JSON_HEDLEY_NON_NULL(...)
    #endif
nemequ commented 3 years ago

Sorry it took me so long to get to this, but thanks for the report!

It looks like this has been fixed since at least IAR 8.5.9; it now returns false. I'm just going to ignore __has_attribute for < 8.5.9, but I'll add explicit tests for the attributes IAR is known to support so this should actually improve the number of situations where we can output the attributes in question.

Unfortunately __has_extension(attribute_deprecated_with_message) is broken (as of 8.5.9); it seems like their feature detection macros are pretty unreliable ☹. I've added an exception for attribute_deprecated_with_message, but for now we still basically trust __has_extension..

This will be included in the next version, which I'll be releasing soon.