Hacker News new | past | comments | ask | show | jobs | submit login
Non-nullable pointers for C++ (github.com/dropbox)
18 points by ingve on July 18, 2015 | hide | past | favorite | 1 comment



Using types to encode additional invariants is of course very useful, though those pointers does not enforce non-nullability. For example you can transfer ownership out of them more than once:

  void f(nn_unique_ptr<std::string> a, nn_unique_ptr<std::string> b) {
    // Null pointer dereference in one of following lines:
    std::cout << *a << std::endl;
    std::cout << *b << std::endl;
  }
  
  int main() {
    std::bind(f, _1, _1)(nn_make_unique<std::string>("Hello!"));
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: