[PATCH] D51380: Fix incorrect usage of std::error_category

Alexandre Ganea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 28 14:00:20 PDT 2018


aganea created this revision.
aganea added reviewers: ilya-biryukov, zturner.
Herald added a subscriber: cfe-commits.

As mentionned here <https://reviews.llvm.org/D50807#inline-449938>, this change prevents a dangling pointer in `std:error_code` by using a singleton.


Repository:
  rC Clang

https://reviews.llvm.org/D51380

Files:
  lib/Frontend/PrecompiledPreamble.cpp


Index: lib/Frontend/PrecompiledPreamble.cpp
===================================================================
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -742,8 +742,10 @@
   return nullptr;
 }
 
+static llvm::ManagedStatic<BuildPreambleErrorCategory> BuildPreambleErrCategory;
+
 std::error_code clang::make_error_code(BuildPreambleError Error) {
-  return std::error_code(static_cast<int>(Error), BuildPreambleErrorCategory());
+  return std::error_code(static_cast<int>(Error), *BuildPreambleErrCategory);
 }
 
 const char *BuildPreambleErrorCategory::name() const noexcept {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51380.162949.patch
Type: text/x-patch
Size: 622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180828/fad5b5da/attachment.bin>


More information about the cfe-commits mailing list