Use std::cerr for folly/Singleton.cpp error printing
authorPhil Willoughby <philwill@fb.com>
Thu, 10 Nov 2016 12:09:21 +0000 (04:09 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Thu, 10 Nov 2016 12:23:37 +0000 (04:23 -0800)
Summary:
Create a local std::ios_base::Init instance to ensure that it is valid, then
use std::cerr.

Reviewed By: yfeldblum, nbronson

Differential Revision: D4139681

fbshipit-source-id: 03377dd417710e320a6b53298d507fd0168592f6

folly/Singleton.cpp

index fe8d7db7a17b38b4e94e43b557fdd972918a04ab..5e89442c01e0a2692b10fe5e38e0c306a0c9c0e9 100644 (file)
 #include <atomic>
 #include <cstdio>
 #include <cstdlib>
 #include <atomic>
 #include <cstdio>
 #include <cstdlib>
-#include <sstream>
+#include <iostream>
 #include <string>
 
 #include <string>
 
-#include <folly/FileUtil.h>
 #include <folly/ScopeGuard.h>
 
 namespace folly {
 #include <folly/ScopeGuard.h>
 
 namespace folly {
@@ -31,13 +30,12 @@ namespace detail {
 
 [[noreturn]] void singletonWarnDoubleRegistrationAndAbort(
     const TypeDescriptor& type) {
 
 [[noreturn]] void singletonWarnDoubleRegistrationAndAbort(
     const TypeDescriptor& type) {
-  // Not using LOG(FATAL) or std::cerr because they may not be initialized yet.
-  std::ostringstream o;
-  o << "Double registration of singletons of the same "
-    << "underlying type; check for multiple definitions "
-    << "of type folly::Singleton<" << type.name() << ">" << std::endl;
-  auto s = o.str();
-  writeFull(STDERR_FILENO, s.data(), s.size());
+  // Ensure the availability of std::cerr
+  std::ios_base::Init ioInit;
+  std::cerr << "Double registration of singletons of the same "
+               "underlying type; check for multiple definitions "
+               "of type folly::Singleton<"
+            << type.name() << ">\n";
   std::abort();
 }
 }
   std::abort();
 }
 }