dist_object<T>.fetch isn't a constant function

Issue #224 resolved
Alexander Ding created an issue

Shouldn’t the fetch function be a constant function given that it is only reading?

int get(dist_object<int> v, int rank) const {
  return v.fetch(rank).wait();
}

doesn’t actually work as fetch isn’t constant.

Comments (4)

  1. Dan Bonachea

    Thanks for the report - you've correctly identified a bug. This function is specified as const, but the implementation is non-conforming.

    Note your example program is ill-formed for two reasons - the const qualifier cannot appear on a free function, and dist_object is not CopyConstructible, so it cannot be passed to a function by value (only by reference or pointer).

    Here is a complete reproducer:

    #include <upcxx/upcxx.hpp>
    #include <iostream>
    
    struct foo {
      upcxx::dist_object<int> v;
      int get(int rank) const {
        return v.fetch(rank).wait();
      }
    };
    
    
    int main() {
      upcxx::init();
    
      const foo f{4};
      int x = f.get(0);
    
      upcxx::finalize();
      return 0;
    }
    
  2. Log in to comment