https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78209
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> --- This seems to fix it: --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -27598,6 +27598,8 @@ do_auto_deduction (tree type, tree init, tree auto_node, else if (AUTO_IS_DECLTYPE (auto_node)) { tree stripped_init = tree_strip_any_location_wrapper (init); + if (REFERENCE_REF_P (stripped_init)) + stripped_init = TREE_OPERAND (stripped_init, 0); bool id = (DECL_P (stripped_init) || ((TREE_CODE (init) == COMPONENT_REF || TREE_CODE (init) == SCOPE_REF) (then id is true and decltype deduces the right type).