Fix compilation on Mac.

Fixes issue 3167.

(cherry picked from commit 4c65b9be351cfe970a4615173a4cef6fbecae559)