[llvm] r218160 - Converting object's error_category to a ManagedStatic to avoid static constructors and destructors.

Chris Bieneman beanz at apple.com
Fri Sep 19 16:28:12 PDT 2014


Yea, I’ve noticed this is a re-occurring pattern. Once we’ve moved our minimum MSVC version up to one that supports C++14’s std::error_category we’ll need to go and clean these up.

-Chris

> On Sep 19, 2014, at 3:44 PM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Fri, Sep 19, 2014 at 3:09 PM, Chris Bieneman <beanz at apple.com <mailto:beanz at apple.com>> wrote:
> Author: cbieneman
> Date: Fri Sep 19 17:09:18 2014
> New Revision: 218160
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=218160&view=rev <http://llvm.org/viewvc/llvm-project?rev=218160&view=rev>
> Log:
> Converting object's error_category to a ManagedStatic to avoid static constructors and destructors.
> 
> Hmm. Pity. In C++14 std::error_category's ctor is required to be constexpr... well, one day when we adopt C++14 we can remove this workaround.
>  
> 
> Modified:
>     llvm/trunk/lib/Object/Error.cpp
> 
> Modified: llvm/trunk/lib/Object/Error.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Error.cpp?rev=218160&r1=218159&r2=218160&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Error.cpp?rev=218160&r1=218159&r2=218160&view=diff>
> ==============================================================================
> --- llvm/trunk/lib/Object/Error.cpp (original)
> +++ llvm/trunk/lib/Object/Error.cpp Fri Sep 19 17:09:18 2014
> @@ -13,6 +13,7 @@
> 
>  #include "llvm/Object/Error.h"
>  #include "llvm/Support/ErrorHandling.h"
> +#include "llvm/Support/ManagedStatic.h"
> 
>  using namespace llvm;
>  using namespace object;
> @@ -48,7 +49,8 @@ std::string _object_error_category::mess
>                     "defined.");
>  }
> 
> +static ManagedStatic<_object_error_category> error_category;
> +
>  const std::error_category &object::object_category() {
> -  static _object_error_category o;
> -  return o;
> +  return *error_category;
>  }
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140919/02894e47/attachment.html>


More information about the llvm-commits mailing list