diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index e205fd0e8fe11652fc3215af79bec6fad20f5f5f..039d07e29b3e721424b223b33929b1eecb5c582e 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -322,8 +322,8 @@ ref<Store> openStore(bool reserveSpace)
     }
 
     return mode == mDaemon
-        ? make_ref<Store, RemoteStore>()
-        : make_ref<Store, LocalStore>(reserveSpace);
+        ? (ref<Store>) make_ref<RemoteStore>()
+        : (ref<Store>) make_ref<LocalStore>(reserveSpace);
 }
 
 
diff --git a/src/libutil/types.hh b/src/libutil/types.hh
index 23eb5251209e3e9c89a73b189df42fe60d1867a8..0eae46c5fe9378ab742cae6a40f30c394f122e6b 100644
--- a/src/libutil/types.hh
+++ b/src/libutil/types.hh
@@ -134,16 +134,18 @@ public:
         return p;
     }
 
+    template<typename T2>
+    operator ref<T2> ()
+    {
+        return ref<T2>((std::shared_ptr<T2>) p);
+    }
+
 private:
 
     template<typename T2, typename... Args>
     friend ref<T2>
     make_ref(Args&&... args);
 
-    template<typename T2, typename T3, typename... Args>
-    friend ref<T2>
-    make_ref(Args&&... args);
-
 };
 
 template<typename T, typename... Args>
@@ -154,13 +156,4 @@ make_ref(Args&&... args)
     return ref<T>(p);
 }
 
-template<typename T, typename T2, typename... Args>
-inline ref<T>
-make_ref(Args&&... args)
-{
-    auto p = std::make_shared<T2>(std::forward<Args>(args)...);
-    return ref<T>(p);
-}
-
-
 }