[libcxx] r191980 - G M: Provides the _LIBCPP_WARNING macro, to be used for MSVC only, since that compiler doesn't support #warning.

Howard Hinnant hhinnant at apple.com
Fri Oct 4 14:14:44 PDT 2013


Author: hhinnant
Date: Fri Oct  4 16:14:44 2013
New Revision: 191980

URL: http://llvm.org/viewvc/llvm-project?rev=191980&view=rev
Log:
G M: Provides the _LIBCPP_WARNING macro, to be used for MSVC only, since that compiler doesn't support #warning.

Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/__undef_min_max
    libcxx/trunk/include/ext/hash_map
    libcxx/trunk/include/ext/hash_set
    libcxx/trunk/src/exception.cpp
    libcxx/trunk/src/thread.cpp

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=191980&r1=191979&r2=191980&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Oct  4 16:14:44 2013
@@ -79,6 +79,9 @@
 #  endif
 #  if defined(_MSC_VER) && !defined(__clang__)
 #    define _LIBCPP_MSVC // Using Microsoft Visual C++ compiler
+#    define _LIBCPP_TOSTRING2(x) #x
+#    define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
+#    define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
 #  endif
 #  // If mingw not explicitly detected, assume using MS C runtime only.
 #  ifndef __MINGW32__

Modified: libcxx/trunk/include/__undef_min_max
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__undef_min_max?rev=191980&r1=191979&r2=191980&view=diff
==============================================================================
--- libcxx/trunk/include/__undef_min_max (original)
+++ libcxx/trunk/include/__undef_min_max Fri Oct  4 16:14:44 2013
@@ -9,11 +9,19 @@
 //===----------------------------------------------------------------------===//
 
 #ifdef min
+#if defined(_MSC_VER) && ! defined(__clang__)
+_LIBCPP_WARNING("macro min is incompatible with C++.  #undefing min")
+#else
 #warning: macro min is incompatible with C++.  #undefing min
+#endif
 #undef min
 #endif
 
 #ifdef max
+#if defined(_MSC_VER) && ! defined(__clang__)
+_LIBCPP_WARNING("macro max is incompatible with C++.  #undefing max")
+#else
 #warning: macro max is incompatible with C++.  #undefing max
+#endif
 #undef max
 #endif

Modified: libcxx/trunk/include/ext/hash_map
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ext/hash_map?rev=191980&r1=191979&r2=191980&view=diff
==============================================================================
--- libcxx/trunk/include/ext/hash_map (original)
+++ libcxx/trunk/include/ext/hash_map Fri Oct  4 16:14:44 2013
@@ -206,7 +206,11 @@ template <class Key, class T, class Hash
 #include <ext/__hash>
 
 #if __DEPRECATED
-#warning Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>
+#if defined(_MSC_VER) && ! defined(__clang__)
+    _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>")
+#else
+#   warning Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>
+#endif
 #endif
 
 #pragma GCC system_header

Modified: libcxx/trunk/include/ext/hash_set
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ext/hash_set?rev=191980&r1=191979&r2=191980&view=diff
==============================================================================
--- libcxx/trunk/include/ext/hash_set (original)
+++ libcxx/trunk/include/ext/hash_set Fri Oct  4 16:14:44 2013
@@ -199,7 +199,11 @@ template <class Value, class Hash, class
 #include <ext/__hash>
 
 #if __DEPRECATED
-#warning Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>
+#if defined(_MSC_VER) && ! defined(__clang__)
+    _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>")
+#else
+#   warning Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>
+#endif
 #endif
 
 namespace __gnu_cxx {

Modified: libcxx/trunk/src/exception.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/exception.cpp?rev=191980&r1=191979&r2=191980&view=diff
==============================================================================
--- libcxx/trunk/src/exception.cpp (original)
+++ libcxx/trunk/src/exception.cpp Fri Oct  4 16:14:44 2013
@@ -1,3 +1,5 @@
+
+
 //===------------------------ exception.cpp -------------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
@@ -39,6 +41,13 @@
   static std::unexpected_handler __unexpected_handler;
 #endif // __has_include(<cxxabi.h>)
 
+_LIBCPP_NORETURN
+static void _libcpp_abort(const char* msg)
+{
+    printf("%s\n", msg);
+    abort();
+}
+
 namespace std
 {
 
@@ -89,15 +98,13 @@ terminate() _NOEXCEPT
 #endif  // _LIBCPP_NO_EXCEPTIONS
         (*get_terminate())();
         // handler should not return
-        printf("terminate_handler unexpectedly returned\n");
-        ::abort ();
+        _libcpp_abort("terminate_handler unexpectedly returned\n");
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
         // handler should not throw exception
-        printf("terminate_handler unexpectedly threw an exception\n");
-        ::abort ();
+        _libcpp_abort("terminate_handler unexpectedly threw an exception\n");
     }
 #endif  // _LIBCPP_NO_EXCEPTIONS
 }
@@ -111,12 +118,16 @@ bool uncaught_exception() _NOEXCEPT
     // on Darwin, there is a helper function so __cxa_get_globals is private
     return __cxa_uncaught_exception();
 #else  // __APPLE__
-    #warning uncaught_exception not yet implemented
-    printf("uncaught_exception not yet implemented\n");
-    ::abort();
+#   if defined(_MSC_VER) && ! defined(__clang__)
+        _LIBCPP_WARNING("uncaught_exception not yet implemented")
+#   else
+#       warning uncaught_exception not yet implemented
+#   endif
+    _libcpp_abort("uncaught_exception not yet implemented\n");
 #endif  // __APPLE__
 }
 
+
 #ifndef _LIBCPPABI_VERSION
 
 exception::~exception() _NOEXCEPT
@@ -149,9 +160,12 @@ exception_ptr::~exception_ptr() _NOEXCEP
 #if HAVE_DEPENDENT_EH_ABI
     __cxa_decrement_exception_refcount(__ptr_);
 #else
-    #warning exception_ptr not yet implemented
-    printf("exception_ptr not yet implemented\n");
-    ::abort();
+#   if defined(_MSC_VER) && ! defined(__clang__)
+        _LIBCPP_WARNING("exception_ptr not yet implemented")
+#   else
+#       warning exception_ptr not yet implemented
+#   endif
+    _libcpp_abort("exception_ptr not yet implemented\n");
 #endif  // __APPLE__
 }
 
@@ -161,9 +175,14 @@ exception_ptr::exception_ptr(const excep
 #if HAVE_DEPENDENT_EH_ABI
     __cxa_increment_exception_refcount(__ptr_);
 #else
-    #warning exception_ptr not yet implemented
-    printf("exception_ptr not yet implemented\n");
-    ::abort();
+
+#   if defined(_MSC_VER) && ! defined(__clang__)
+        _LIBCPP_WARNING("exception_ptr not yet implemented")
+#   else
+#       warning exception_ptr not yet implemented
+#   endif
+    _libcpp_abort("exception_ptr not yet implemented\n");
+
 #endif  // __APPLE__
 }
 
@@ -178,9 +197,14 @@ exception_ptr& exception_ptr::operator=(
     }
     return *this;
 #else  // __APPLE__
-    #warning exception_ptr not yet implemented
-    printf("exception_ptr not yet implemented\n");
-    ::abort();
+
+#   if defined(_MSC_VER) && ! defined(__clang__)
+        _LIBCPP_WARNING("exception_ptr not yet implemented")
+#   else
+#       warning exception_ptr not yet implemented
+#   endif
+    _libcpp_abort("exception_ptr not yet implemented\n");
+
 #endif  // __APPLE__
 }
 
@@ -213,9 +237,12 @@ exception_ptr current_exception() _NOEXC
     ptr.__ptr_ = __cxa_current_primary_exception();
     return ptr;
 #else  // __APPLE__
-    #warning exception_ptr not yet implemented
-    printf("exception_ptr not yet implemented\n");
-    ::abort();
+#   if defined(_MSC_VER) && ! defined(__clang__)
+        _LIBCPP_WARNING( "exception_ptr not yet implemented" )
+#   else
+#       warning exception_ptr not yet implemented
+#   endif
+    _libcpp_abort("exception_ptr not yet implemented\n");
 #endif  // __APPLE__
 }
 
@@ -227,9 +254,12 @@ void rethrow_exception(exception_ptr p)
     // if p.__ptr_ is NULL, above returns so we terminate
     terminate();
 #else  // __APPLE__
-    #warning exception_ptr not yet implemented
-    printf("exception_ptr not yet implemented\n");
-    ::abort();
+#   if defined(_MSC_VER) && ! defined(__clang__)
+        _LIBCPP_WARNING("exception_ptr not yet implemented")
+#   else
+#       warning exception_ptr not yet implemented
+#   endif
+    _libcpp_abort("exception_ptr not yet implemented\n");
 #endif  // __APPLE__
 }
 } // std

Modified: libcxx/trunk/src/thread.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=191980&r1=191979&r2=191980&view=diff
==============================================================================
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Fri Oct  4 16:14:44 2013
@@ -89,7 +89,11 @@ thread::hardware_concurrency() _NOEXCEPT
 #else  // defined(CTL_HW) && defined(HW_NCPU)
     // TODO: grovel through /proc or check cpuid on x86 and similar
     // instructions on other architectures.
-#warning hardware_concurrency not yet implemented
+#   if defined(_MSC_VER) && ! defined(__clang__)
+        _LIBCPP_WARNING("hardware_concurrency not yet implemented")
+#   else
+#       warning hardware_concurrency not yet implemented
+#   endif
     return 0;  // Means not computable [thread.thread.static]
 #endif  // defined(CTL_HW) && defined(HW_NCPU)
 }





More information about the cfe-commits mailing list