1. Class derived has access to public (and protected) members of class base, by the rules of public inheritance.
2. Members of class base have access to all other base members, because they belong to the same class.
 d.pub_fun(); is valid because of 1. and int base::pub_fun() { cout << priv_var << "\n"; } is valid because of 2. so everything compiles and works without a problem.
I was expecting the following code snippet to give compile error since derived class will not have priv_var which I am trying to access in pub_fun().
You are conflating two separate steps into one here. The derived class does indeed not have access to base::priv_var, but derived never attempts to use base::priv_var. All that derived d; does is call the public member function pub_fun(). From there on it is a matter of pub_fun implementation, which derived needs not know or care about. In your example, the implementation of pub_fun happens to use a private base variable, which it is perfectly fine to do since it is a member function of the same base class.
In other cases, class derived could be your code, and base could be a library class to which you don't even have the source code. You could always call public member functions from base even though you would have no idea what their implementation uses internally.
     
    
int base::pub_fun()does not return anintas declared.