"Robert Ramey" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hmmmm - I never imagined that something like this would be so problematic. > > For now with my VC 7.0 compiler I can use the following and it gives > me almost exactly what I need. The warning message points exactly > to the place in my code where I have invoked it - just like BOOST_STATIC_ASSERT. > > I would hope something like this could be boostified so that I could use it outside > of a function. > > template<bool> > struct warning > { > typedef int type; > }; > > template<> > struct warning<true> > { > typedef char type; > }; > > #define BOOST_STATIC_WARNING(B) \ > { \ > char x = (warning<B>::type)0xffff; \ > } > Played with, it works on Intel C++ 7 and MSVC 6 (two warnings issued).
It doesn't work for BC++B and needs change, e.g.: #ifdef __BORLANDC__ template<bool> struct warning { typedef int& type }; template<> struct warning<true> { typedef int type; }; #define BOOST_STATIC_WARNING(B) \ { \ warning<B>::type compile_time_warning_issued = 0; \ compile_time_warning_issued = compile_time_warning_issued; \ } #endif (It produces warning "temporary used to initialize 'compile_time_warning_issued'.) It would not work if #pragma warn -8028 is defined. I thought about preprocessor based solution (for compilers supporting #pragma message): ------------ file test.cpp: #include <boost/preprocessor.hpp> #define BOOST_STATIC_WARNING(x) \ BOOST_PP_STRINGIZE( BOOST_PP_CAT( BOOST_PP_CAT(warning, BOOST_PP_BOOL(x) ), .hpp ) ) int main() { #define BOOST_STATIC_WARNING_TEXT "detailed warning description" #include BOOST_STATIC_WARNING(0) } ------------ file warning0.hpp: #ifndef BOOST_STATIC_WARNING_TEXT #error You must define BOOST_STATIC_WARNING_TEXT each time before using BOOST_STATIC_WARNING #endif #ifdef _MSC_VER # pragma message ("COMPILE TIME WARNING: " BOOST_STATIC_WARNING_TEXT) #endif #undef BOOST_STATIC_WARNING_TEXT ------------ file warning1.hpp: #ifndef BOOST_STATIC_WARNING_TEXT #error You must define BOOST_STATIC_WARNING_TEXT each time before using BOOST_STATIC_WARNING #endif #undef BOOST_STATIC_WARNING_TEXT ------------ Output (Intel C++ 7.0 plugged in MSVC 6 IDE, MSVC 6 as well): --------------------Configuration: test - Win32 Debug-------------------- Compiling... test.cpp COMPILE TIME WARNING: detailed warning description Linking... link: executing 'C:\PROGRA~1\Microsoft Visual Studio\VC98\Bin\link.exe' test.exe - 0 error(s), 1 warning(s) It cannot be used to generate warnings for template instantiations etc. /Pavel _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost