In the US, discussion of pay and working conditions while on the job and off are protected acts under the NLRA. The NLRB is the board that enforces those protections.
Can you waive those protections away by signing a contract that contains a clause that forbids salary discussions, or would that clause of the contract become unenforceable?
It would be unenforceable, with the caveat that the protection only applies to non-supervisory roles and only when discussing salary with other employees internally. Companies can still limit your ability to disclose your salary externally, as a trade secret.