add -Werror=declaration-after-statement only to stdlib extension modules (closes #21121)

Patch from Stefan Krah.