yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
884 stars 112 forks source link

Linux/gcc 8.4: core dump with example code #143

Closed SpaceIm closed 3 years ago

SpaceIm commented 3 years ago

I have hard time trying to add cpp-peglib 1.3.0 in conan public repo https://github.com/conan-io/conan-center-index/pull/4411 First I had some issues with gcc 7 because cpp-peglib includes charconv (requires gcc >= 8.1), so I dropped gcc 7. With gcc 8.4 our simple test (the How to use example in README) fails at runtime:

terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted (core dumped)

Do you know the minimum mainstream compiler version for cpp-peglib >= 1.0.0 (Visual Studio, gcc, clang and apple-clang)?

yhirose commented 3 years ago

@SpaceIm, could you try 1.3.1?

Do you know the minimum mainstream compiler version for cpp-peglib >= 1.0.0 (Visual Studio, gcc, clang and apple-clang)?

It requires compilers that support C++17.

SpaceIm commented 3 years ago

It compiles now with gcc7 and 1.3.1, but I have different type of errors depending on the compiler (runtime error with gcc >= 7, link errors with clang 7 and libstdc++, compilation error with clang 5):

Linux (gcc and clang): https://github.com/SpaceIm/conan-cpp-peglib/actions/runs/521412652 Windows (MinGW and Visual Studio, looks good): https://ci.appveyor.com/project/SpaceIm/conan-cpp-peglib/builds/37514230 (don't look at gcc < 7, clang < 5, or Visual Studio < 2017)

yhirose commented 3 years ago

@SpaceIm, thanks for the info. I now only care for compliers whose __cplusplus shows equal greater than '201703L', since my workplace completely switched to C++17 compliers on Windows (Visual Studio 2019), Mac (apple-clang on XCode), Linux (clang 11.0) and encourages developers to use C++17 features, so that the code could be more concise and readable.

Just in case users want to user peglib with C++11 compilers, I made the C++11 branch (https://github.com/yhirose/cpp-peglib/tree/cpp11). But it is just a snapshot right before the version 1.0, and I no longer maintain the branch.

Sorry for causing inconveniences on your side. But I don't have time to support all the compilers existing... Of course any pull requests are welcome to fix the build errors. Thanks for your help!

SpaceIm commented 3 years ago

@yhirose I guess you didn't look at my Linux tests 😉, but it also fails at runtime for all gcc version upto 9, which has full C++17 support (didn't test gcc 10).

Moreover all versions I've mentioned (gcc>=7, clang >=5 and msvc >=2017) show a __cplusplus equal or greater than '201703L' when appropriate stdc++ flags are set (I set CXX_STANDARD 17 with CMake). Basically:

Well, in conan recipe, I can raise a little bit minimum versions of compilers (far more than their minimum version with "almost complete" C++17 support), but I need also to drop gcc on Linux which is a little bit weird.

yhirose commented 3 years ago

@SpaceIm, thank you for the details. I just compiled the sample on README with g++ 9.3.0 and clang++ 10.0.0 on Ubuntu 20.04 and both compilers worked fine.

Here is the command that I did.

g++ -std=c++17 -o sample sample.cc -I. -pthread && ./sample
clang++ -std=c++17 -o sample sample.cc -I. -pthread && ./sample

Could you make sure to build with -pthread? (You can see 'IMPORTANT NOTE' for Linux build in README.) If you get the same error even if you link pthread, please let me know. Thanks.

SpaceIm commented 3 years ago

Oh, you're right, I was doing -lpthread at link time, not -pthread. Thanks.

Now it works, except for clang 7 / libstdc++ (works fine with clang 7/libc++, and clang 6 or 8+):

/usr/bin/ld: CMakeFiles/test_package.dir/test_package.cpp.o: in function `std::_Function_handler<std::any (peg::SemanticValues&, std::any&), peg::Action::make_adaptor<peg::ParserGenerator::setup_actions()::{lambda(peg::SemanticValues const&)#7}>(peg::ParserGenerator::setup_actions()::{lambda(peg::SemanticValues const&)#7})::{lambda(std::function<std::any (peg::SemanticValues&, std::any&)>&, auto:2&)#1}>::_M_invoke(std::_Any_data const&, peg::SemanticValues&, std::any&)':
test_package.cpp:(.text._ZNSt17_Function_handlerIFSt3anyRN3peg14SemanticValuesERS0_EZNS1_6Action12make_adaptorIZNS1_15ParserGenerator13setup_actionsEvEUlRKS2_E5_EESt8functionIS5_ET_EUlRSE_RT0_E_E9_M_invokeERKSt9_Any_dataS3_S4_[_ZNSt17_Function_handlerIFSt3anyRN3peg14SemanticValuesERS0_EZNS1_6Action12make_adaptorIZNS1_15ParserGenerator13setup_actionsEvEUlRKS2_E5_EESt8functionIS5_ET_EUlRSE_RT0_E_E9_M_invokeERKSt9_Any_dataS3_S4_]+0x78): undefined reference to `__muloti4'
yhirose commented 3 years ago

@SpaceIm, from 1.0.0, I simplified cpp-peglib code a lot with C++17 features, and it seems like clang7/libstdc++ doesn't compile the code. Since I don't use the combination, I am ok to leave it as it is. If you can easily find what causes the error, please let me know, otherwise I am ok to exclude it from the configuration.

yhirose commented 3 years ago

Maybe this is similar to this? https://stackoverflow.com/questions/49793632/clang-fsanitize-undefined-with-128-integer-operations-undefined-reference-to

SpaceIm commented 3 years ago

Yes, I saw this issue, it looks similar, but didn't find any workaround. For the moment, cpp-peglib recipe in conan center prevents to use it with clang 7 and libstdc++, it's fine for us.

I close this issue, thanks for your help.