Search code examples
boostcompilationboost-xpressive

path of regex_byref_matcher.hpp when using xp::sregex::compile


I noticed that when I use xp::sregex::compile in my code, the string ...\3rdparty\boost-1_58\boost/xpressive/detail/core/matcher/regex_byref_matcher.hpp (with my local path) appears in the binary code, compiled in release mods. Is there a way to remove it?


Solution

  • This is undoubtedly when the code uses __FILE__ to get nice assert/exception messages.

    The only place where Xpressive uses it directly is in regex_error.hpp:

    #define BOOST_XPR_ENSURE_(pred, code, msg)                                                          \
        boost::xpressive::detail::ensure_(!!(pred), code, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)  \
        /**/
    

    You could easily hack it to be

    #include <boost/xpressive/regex_error.hpp>
    
    #undef BOOST_XPR_ENSURE_
    
    #define BOOST_XPR_ENSURE_(pred, code, msg)                                                          \
        boost::xpressive::detail::ensure_(!!(pred), code, msg, BOOST_CURRENT_FUNCTION, "(source-hidden)", __LINE__)  \
        /**/
    

    Keep in mind:

    • the hack needs to go before any other Xpressive includes
    • this will limit the usefulness of the messages, should they occur
    • there is a possibility that one of the libraries that Xpressive depends on uses similar constructs