https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94553

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
To fix CWG 2289, we need this:

--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -1705,6 +1705,9 @@ duplicate_decls (tree newdecl, tree olddecl, bool
newdecl_is_friend)
      inform (olddecl_loc, "previous declaration %q#D", olddecl);
      return error_mark_node;
    }
+      else if ((VAR_P (olddecl) && DECL_DECOMPOSITION_P (olddecl))
+          || (VAR_P (newdecl) && DECL_DECOMPOSITION_P (newdecl)))
+   /* A structured binding must be unique in its declarative region.  */;
       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
           || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    /* One is an implicit typedef, that's ok.  */


but that's not enough to detect the 'A' case:
cp_parser_decomposition_declaration
uses

13968       tree decl2 = start_decl (declarator, &decl_specs, SD_INITIALIZED,
13969                                NULL_TREE, NULL_TREE, &elt_pushed_scope);

to create the 'A' VAR_DECL but in this start_decl's grokdeclarator we don't do
fit_decomposition_lang_decl because the declarator kind is not cdk_decomp, so
then when start_decl calls maybe_push_decl, the decl 'A' isn't
DECL_DECOMPOSITION_P and we don't detect this case.  So we need a way to signal
to start_decl that it should fit_decomposition_lang_decl.

Reply via email to