For new Confluence Cloud, according to the documentation adding an anchor to a heading with an expand section is not precluded. However, there is no 'hover over pop-up' link to the heading within these sections. This is required to add the anchor link.