Fix `static_assert()` scope in `CombinedAllocator`.
authorDan Liew <dan@su-root.co.uk>
Fri, 21 Dec 2018 21:41:37 +0000 (21:41 +0000)
committerDan Liew <dan@su-root.co.uk>
Fri, 21 Dec 2018 21:41:37 +0000 (21:41 +0000)
It should be at the class scope and not inside the `Init(...)` function
because we want to error out as soon as the wrong type is constructed.
At the function scope the `static_assert` is only checked if the
function might be called.

This is a follow up to r349957.

rdar://problem/45284065

llvm-svn: 349960

compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h

index 2dec5d8..91e4684 100644 (file)
@@ -26,6 +26,13 @@ template <class PrimaryAllocator, class AllocatorCache,
 class CombinedAllocator {
  public:
   using AddressSpaceView = AddressSpaceViewTy;
+  static_assert(is_same<AddressSpaceView,
+                        typename PrimaryAllocator::AddressSpaceView>::value,
+                "PrimaryAllocator is using wrong AddressSpaceView");
+  static_assert(is_same<AddressSpaceView,
+                        typename SecondaryAllocator::AddressSpaceView>::value,
+                "SecondaryAllocator is using wrong AddressSpaceView");
+
   void InitLinkerInitialized(s32 release_to_os_interval_ms) {
     primary_.Init(release_to_os_interval_ms);
     secondary_.InitLinkerInitialized();
@@ -33,12 +40,6 @@ class CombinedAllocator {
   }
 
   void Init(s32 release_to_os_interval_ms) {
-    static_assert(is_same<AddressSpaceView,
-                          typename PrimaryAllocator::AddressSpaceView>::value,
-                  "PrimaryAllocator is using wrong AddressSpaceView");
-    static_assert(is_same<AddressSpaceView,
-                          typename SecondaryAllocator::AddressSpaceView>::value,
-                  "SecondaryAllocator is using wrong AddressSpaceView");
     primary_.Init(release_to_os_interval_ms);
     secondary_.Init();
     stats_.Init();