Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing include to fix build for some compilers #368

Merged
merged 1 commit into from
Aug 18, 2024

Conversation

felixguendling
Copy link
Contributor

On some compilers / standard library combinations (e.g. Mac OS) the build does not work
This adds missing includes and fixes the build.

@uilianries
Copy link
Member

@felixguendling Hello! Thank you for your contribution. Could you please share the error output that you are trying to fix? When you say MacOS, which compiler and version are you using? Regards!

@felixguendling
Copy link
Contributor Author

felixguendling commented Aug 15, 2024

std::throw_with_nested is part of the #include <exception> header which is not included. So that it works with libstdc++ is more a coincidence and might change in the future. With the latest AppleClang version as well as Clang 17 with -stdlib=libc++ it produces compilation errors that it can't find std::throw_with_nested.

@felixguendling
Copy link
Contributor Author

Compiler output on MacOS:

/Users/felix/code/oh/deps/PEGTL/include/tao/pegtl/normal.hpp:70:18: error: no member named 'throw_with_nested' in namespace 'std'
            std::throw_with_nested( parse_error( Rule::error_message, am ) );
            ~~~~~^
/Users/felix/code/oh/deps/PEGTL/include/tao/pegtl/normal.hpp:73:18: error: no member named 'throw_with_nested' in namespace 'std'
            std::throw_with_nested( parse_error( "parse error matching " + std::string( demangle< Rule >() ), am ) );
            ~~~~~^
2 errors generated.

Version:

c++ --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

PS: I'm using PEGTL to parse OpenStreetMap like opening hours (example). It's really simple to use and I didn't expect compilation times to be so fast. Thank you for providing this library!

@uilianries
Copy link
Member

@felixguendling Thank you for providing such details!

@uilianries uilianries requested a review from ColinH August 15, 2024 16:14
@d-frey
Copy link
Member

d-frey commented Aug 15, 2024

This is IMHO not the correct fix. <exception> is included several lines below in the header iff __cpp_exceptions is set. The PEGTL supports compiling with -fno-exception and therefore, you should #if-... the parts where throw_with_nested is used. CC @ColinH

@felixguendling
Copy link
Contributor Author

Looking at the #if defined(__cpp_exceptions ) part, it looks like the #include <exception> statement has already been there, just in the wrong branch if the preprocessor #if?

#if defined( __cpp_exceptions )
#include "demangle.hpp"
#else
#include "internal/dependent_false.hpp"
#include <exception>
#endif

@d-frey d-frey assigned d-frey and unassigned ColinH Aug 15, 2024
@d-frey
Copy link
Member

d-frey commented Aug 15, 2024

Right. I think this is due to the addition of raise_nested which was only added after the infrastructure for -fno-exception support was already in place. So please update you PR to remove the second guarded inclusion of <exception>, as the first global one should now be correct and sufficient.

@felixguendling
Copy link
Contributor Author

I changed it. This looks better now (and still works for me).

@d-frey d-frey assigned ColinH and unassigned d-frey Aug 16, 2024
@d-frey
Copy link
Member

d-frey commented Aug 16, 2024

@ColinH I assigned it back to you, as the main branch is currently your playground. The PR is OK from my side.

@ColinH
Copy link
Member

ColinH commented Aug 18, 2024

Right, thanks everybody, we can merge this. I'll manually update the work branch where the fun is happening.

@ColinH ColinH merged commit 1c1aa6e into taocpp:main Aug 18, 2024
56 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants