Guard potentially unused variable

Closes #4083.