Skip to content

Commit

Permalink
Fix "-Wundef" warning when building as C++20
Browse files Browse the repository at this point in the history
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 martinmoene#84.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
  • Loading branch information
simark committed May 6, 2024
1 parent 50f55c5 commit 6a5024b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/nonstd/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ using span_lite::byte_span;

#endif // span_FEATURE( BYTE_SPAN )

#if span_HAVE( STRUCT_BINDING )
#if defined(span_HAVE_STRUCT_BINDING) && span_HAVE( STRUCT_BINDING )

#if span_CPP14_OR_GREATER
# include <tuple>
Expand Down

0 comments on commit 6a5024b

Please sign in to comment.