martinmoene / span-lite

span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
495 stars 40 forks source link

Fix "-Wundef" warning when building as C++20 #85

Closed simark closed 1 month ago

simark commented 2 months ago

When including span.hpp in a source file compiled as C++20, I get an error similar to this:

$ g++ -x c++-header span.hpp -Wundef -Werror -std=c++20
span.hpp:43:33: error: "span_HAVE_STRUCT_BINDING" is not defined, evaluates to 0 [-Werror=undef]
   43 | #define span_HAVE( feature )  ( span_HAVE_##feature )
      |                                 ^~~~~~~~~~
span.hpp:1873:5: note: in expansion of macro ‘span_HAVE’
 1873 | #if span_HAVE( STRUCT_BINDING )
      |     ^~~~~~~~~

Fix it by checking if span_HAVE_STRUCT_BINDING is defined. Unfortunately, I couldn't find a way to make defined() work with span_HAVE( STRUCT_BINDING ).

An alternative would be to move the definition of span_HAVE_STRUCT_BINDING outside of the span_USES_STD_SPAN ifdef.

Fixes #84.

cclauss commented 1 month ago

Git conflicts.

martinmoene commented 1 month ago

Fixed via b8921715cd71997bdab120a8ced526b78d300196.