Single-character preprocessor macro in cpprest/details/basic_types.h breaks Boost::iostreams

Apr 24, 2015 at 9:19 PM
Edited Apr 25, 2015 at 9:14 PM
(Opened issue #369.)

On Linux, this simple test program fails to compile:
#include <cpprest/asyncrt_utils.h>
#include <boost/iostreams/copy.hpp>
After a great deal of header-file searching, I determined the actual conflict to be:
#include <cpprest/details/basic_types.h>
#include <boost/iostreams/detail/access_control.hpp>
The actual problem: At the bottom of cpprest/details/basic_types.h appear these three lines:
#define U(x) _XPLATSTR(x)
Meanwhile, in /usr/include/boost/iostreams/detail/access_control.hpp:
    template<typename U>
    struct prot_ : protected U
        prot_() { }
        template<typename V> prot_(V v) : U(v) { }
Your use of a single character name for a preprocessor macro totally breaks this innocent piece of code.
Apr 27, 2015 at 4:44 PM
Hi jasonzio,

Yes we have a macro 'U' for creating a platform dependent string in the library. The library contains the ability to turn the macro off, so in this case it is probably your best choice. Just define _TURN_OFF_PLATFORM_STRING before including any of our headers.

Apr 30, 2015 at 4:41 PM
It doesn't play nicely with Intel TBB either. That platform-dependent string is really, really useful for unit tests though. We just made a new macro in another header:

ifndef USTR_HPP

define USTR_HPP

include "cpprest/details/basic_types.h"

namespace utility
#define USTR(x) _XPLATSTR(x)
}// namespace utility


You can then just search-replace to use USTR. Still short and easy to type.