Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Turning off clang unsafe buffer warnings fails when compiling with a gcc based compiler #1148

@pirgia

Description

@pirgia

The code sections (in span and util)

// Turn off clang unsafe buffer warnings as all accessed are guarded by runtime checks
#if defined(__clang__) && __has_warning("-Wunsafe-buffer-usage")
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif // defined(__clang__) && __has_warning("-Wunsafe-buffer-usage")

and (similarly)

#if defined(__clang__) && __has_warning("-Wunsafe-buffer-usage")
#pragma clang diagnostic pop
#endif

fails when compiling with a GCC-based compiler (the STM compiler for an STM32 microcontroller in this case).
The generated error is:

missing binary operator before token "("

I solved this by separating the checks:

// Turn off clang unsafe buffer warnings as all accessed are guarded by runtime checks
#if defined(__clang__)
#  if __has_warning("-Wunsafe-buffer-usage")
#    pragma clang diagnostic push
#    pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#  endif // __has_warning("-Wunsafe-buffer-usage")
#endif // defined(__clang__)

There are 4 points that need to be modified:

  • span: lines 67 and 855
  • util: lines 45 and 163

Thanks for your attention

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions