Opened 7 years ago
Closed 7 years ago
#11918 closed Bugs (duplicate)
access violation when using string literals with lambda style formatting expressions
Reported by: | Owned by: | Andrey Semashev | |
---|---|---|---|
Milestone: | To Be Determined | Component: | log |
Version: | Boost 1.60.0 | Severity: | Regression |
Keywords: | formatting | Cc: |
Description
The code below crashes with an access violation when using the BOOST_LOG_SEV macro. I'm using boost 1.60 compiled with msvc-10.0.
#include <boost/log/trivial.hpp> #include <boost/log/sinks.hpp> #include <boost/log/expressions.hpp> #include <boost/log/expressions/formatters.hpp> #include <boost/log/attributes.hpp> #include <boost/core/null_deleter.hpp> #include <iostream> #define BOOST_TEST_MODULE TestsLogging #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(example_lib_log) BOOST_AUTO_TEST_CASE(severity_logging_min) { namespace src = ::boost::log::sources; namespace keywords = ::boost::log::keywords; namespace expr = boost::log::expressions; namespace attributes = boost::log::attributes; //sink backend setup typedef boost::log::sinks::text_ostream_backend text_ostream_backend; boost::shared_ptr<text_ostream_backend> backend = boost::make_shared<text_ostream_backend>(); backend->add_stream(boost::shared_ptr<std::ostream>(&std::cerr, boost::null_deleter())); backend->auto_flush(true); //sink frontend setup typedef boost::log::sinks::synchronous_sink<text_ostream_backend> synchronous_sink_text_ostream_backend; boost::shared_ptr<synchronous_sink_text_ostream_backend> sink(new synchronous_sink_text_ostream_backend(backend)); sink->set_formatter(expr::stream << "[" << expr::message); //problem is here boost::log::core::get()->add_sink(sink); //logger setup typedef src::severity_logger<boost::log::trivial::severity_level> severity_logger; severity_logger lg; //logging function BOOST_LOG_SEV(lg, boost::log::trivial::debug) << "First entry."; //exception happens here boost::log::core::get()->remove_sink(sink); } BOOST_AUTO_TEST_SUITE_END()
- When I remove the line where the formatter for the sink is set, the code works fine.
- When I remove the string literal "[" from the stream (expr::stream << expr::message), the code works fine.
- When i move the string literal to the end (expr::stream << expr::message << "[") the code also works.
- The code works with boost 1.57.
Change History (6)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
i've just tried to run it on msvc-14. It works aswell. I've found a workaround for msvc-10 that suits my needs. By passing a custom formatting function to the sinks set_formatter function, conditional formatting + string literals at the beginning of the stream are possible. I've spent 2 days to figure out that the problem is not with the code :(
comment:2 by , 7 years ago
i've just tried to run it on msvc-14. It works aswell. I've found a workaround for msvc-10 that suits my needs. By passing a custom formatting function to the sinks set_formatter function, conditional formatting + string literals at the beginning of the stream are possible. I've spent 2 days to figure out that the problem is not with the code :(
comment:3 by , 7 years ago
This got also reported on Boost.User for MSVC11: http://thread.gmane.org/gmane.comp.lib.boost.user/85258
comment:5 by , 7 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Works without a problem for me on gcc 5.2. Looks like a specific compiler issue to me.