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

Compile errors with clang10 and libc++ #55

Closed AndWass closed 4 years ago

AndWass commented 4 years ago

When trying to use your library with clang10 and libc++ and c++2a I get some compile errors for missing function-like macro span_HAVE. It works with clang9 and libc++ and c++2a though. Godbolt showcasing the issue (against 0.7.0, but errors also relevant on master branch): https://godbolt.org/z/yWWR6Z

Compile errors:


x86-64 clang 10.0.0 (Editor #1, Compiler #1) C++
x86-64 clang 10.0.0
-stdlib=libc++ -std=c++2a
1
<Compilation failed>
x86-64 clang 10.0.0 - 1422ms
#1 with x86-64 clang 10.0.0
nonstd/span.hpp:1523:61: error: function-like macro 'span_HAVE' is not defined

#if span_CPP11_OR_GREATER && span_FEATURE( BYTE_SPAN ) && ( span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) )

                                                            ^

nonstd/span.hpp:1553:5: error: function-like macro 'span_HAVE' is not defined

#if span_HAVE( STRUCT_BINDING )
martinmoene commented 4 years ago

Thanks @AndWass ,

The problem is in the handling of the case where the C++20 standard header <span> is available as with the following configuration it does compile:

-Dspan_CONFIG_SELECT_SPAN=span_SPAN_NONSTD -stdlib=libc++ -std=c++2a

The error only appears with libc++, because only that library provides header <span> apparently.

I'll look into it further.

Arghnews commented 4 years ago

@martinmoene I noticed the same error using clang(d) 10.0.0

[clang pp_expr_bad_token_lparen] [E] In included file: function-like macro 'span_HAVE' is not defined

My simple fix was to move line 281: #define span_HAVE( feature ) ( span_HAVE_##feature ) to precede what I believe is its first use on line 32 # define span_CONFIG_SELECT_SPAN ( span_HAVE_STD_SPAN ? span_SPAN_STD : span_SPAN_NONSTD )

This gets rid of the error in clangd and also compiles without any issue with clang++ -stdlib=libc++ -std=c++2a -Wall sp_test.cpp that contains #include <nonstd/span.hpp>

AndWass commented 4 years ago

Can confirm that this fixed the issue for me as well

martinmoene commented 4 years ago

@AndWass thanks for bringing this to my attention, and @Arghnews much appreciated your solution which is now in head. Sorry for my delayed reaction.

Arghnews commented 4 years ago

Cheers, and thanks for the awesome library.

AndWass commented 4 years ago

Thanks for the fix! Much appreciated :)