boostorg / leaf

Lightweight Error Augmentation Framework
Boost Software License 1.0
312 stars 48 forks source link

BOOST_LEAF_CFG_CAPTURE must be 1 for single-header build to compile #46

Closed dnmiller closed 2 years ago

dnmiller commented 2 years ago

If BOOST_LEAF_CFG_CAPTURE is 0, then <memory> isn't included, but the code that uses std::shared_ptr is not stripped out by the preprocessor, causing a build failure.

This is from a single-header build with this at the top: // Generated on 05/27/2022 from https://github.com/boostorg/leaf/tree/5e9a5b9.

zajo commented 2 years ago

Thanks for reporting this.

zajo commented 2 years ago

I see a bug in LEAF where if you have BOOST_LEAF_CFG_CAPTURE=0, it attempts to use std::shared_ptr in exception.hpp, which leads to a compile error. However, everything in exception.hpp is turned off if exceptions are disabled. I'll fix this, but can you confirm that the configuration I'm describing is what you're using when you get the error?

dnmiller commented 2 years ago

Yep, that's it:

boost/leaf/exception.hpp:52:14: error: 'shared_ptr' in namespace 'std' does not name a template type
boost/leaf/exception.hpp:52:9: note: 'std::shared_ptr' is defined in header '<memory>'; did you forget to '#include <memory>'?
zajo commented 2 years ago

Yeah, OK. I'll remove the shared_ptr from there, it was rather inefficient anyway. I'm curious about your platform if you don't mind me asking, it's surprising to want BOOST_LEAF_CFG_CAPTURE=0 but also not disable exception handling.

zajo commented 2 years ago

This is fixed, merged into the master branch, will ship with Boost 1.80.0.

dnmiller commented 2 years ago

I'm curious about your platform if you don't mind me asking, it's surprising to want BOOST_LEAF_CFG_CAPTURE=0 but also not disable exception handling.

I had actually just included it in an existing project to mess around with and was not paying much attention to the compiler flags...