The problem is that pop() calls the destructor for the removed item, so if you store the return value from front() as a reference and then call pop(), you end up with a dangling reference.

Can it really be possible that with the STL implementation there's no way to store and later remove an item from a queue without ever making a copy? I'll have to investigate a bit...it would be useful in general (and not just for this pull request) to know the canonical answer to this.