The main problem in this PR was that build_const_cast_1 hadn't been updated to support rvalue references, so the first patch does that. The second patch fixes a couple of minor issues that I noticed while investigating this; neither of them should affect observable semantics, but they match the standard better. Tested x86_64-pc-linux-gnu, applying to trunk.