Share tags2

Supersedes #11351.
Variables should not be assigned inside an if