I work for more than a decade now and I still am unsure about what rule to follow. Here are a few things that I have seen happening: I once believed in transparency about that. I told my salary to a friend I just helped to get hired in the company where I already had a few years of experience. Upon hearing my higher salary, he immediately went to my boss to ask for a raise. Due to an incredible incompetence of the HR…
But I know this:
Information is king and it helps to be flexible (abillity to move for a job, ability to start there quickly, ability to be out of a job for weeks/months ...).
I try to do this: advise colleagues that I think should earn more, what to do, what expectations are ok, without destroying team morale and my (selfish) status (knowing that I earn top).