clover: Fix clover::keys and ::values to deal with r-value references properly.
authorFrancisco Jerez <currojerez@riseup.net>
Tue, 14 Jan 2014 21:03:57 +0000 (22:03 +0100)
committerFrancisco Jerez <currojerez@riseup.net>
Wed, 15 Jan 2014 15:48:37 +0000 (16:48 +0100)
Returning a reference is incorrect if the specified pair was a
temporary -- Instead of that, use decltype() to deduce the correct
return type qualifiers.  Fixes a crash in clCreateProgramWithBinary().

Reported-and-tested-by: "Dorrington, Albert" <albert.dorrington@lmco.com>
src/gallium/state_trackers/clover/util/functional.hpp

index 8e0b483a78fdeb60f7b32b825dfca19c3bded6d8..2d8c4c44131b7b43b925591f6724bf9cd6d2bb2c 100644 (file)
@@ -289,17 +289,17 @@ namespace clover {
 
    struct keys {
       template<typename P>
-      typename std::remove_reference<P>::type::first_type &
-      operator()(P &&p) const {
-         return p.first;
+      auto
+      operator()(P &&p) const -> decltype(std::get<0>(std::forward<P>(p))) {
+         return std::get<0>(std::forward<P>(p));
       }
    };
 
    struct values {
       template<typename P>
-      typename std::remove_reference<P>::type::second_type &
-      operator()(P &&p) const {
-         return p.second;
+      auto
+      operator()(P &&p) const -> decltype(std::get<1>(std::forward<P>(p))) {
+         return std::get<1>(std::forward<P>(p));
       }
    };