No slicing will occur in your example:
Foo *f = new Foo();
Bar *b = new Bar();
f = b;
You're assigning the pointer, not the value. The f pointer and the b pointer are the same size (the size of a pointer on the architecture you're running on), so they will always fit into each other with no slicing. The objects themselves aren't affected by this assignment and are not sliced.
But this would cause the 'new Foo()' to leak. After the assignment, both f and b will point to the 'new Bar()' and you'll have no pointer left to the 'new Foo()' which you would be able to delete it with.
Can I suggest you use std::unique_ptr instead of raw pointers. This will take care of deleting for you.
std::unique_ptr<Foo> newInstance()
{
return new Foo();
}