https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79548
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- initialize_local_var has: /* Compute and store the initial value. */ already_used = TREE_USED (decl) || TREE_USED (type); if (TREE_USED (type)) DECL_READ_P (decl) = 1; ... /* Set this to 0 so we can tell whether an aggregate which was initialized was ever used. Don't do this if it has a destructor, so we don't complain about the 'resource allocation is initialization' idiom. Now set attribute((unused)) on types so decls of that type will be marked used. (see TREE_USED, above.) */ if (TYPE_NEEDS_CONSTRUCTING (type) && ! already_used && TYPE_HAS_TRIVIAL_DESTRUCTOR (type) && DECL_NAME (decl)) TREE_USED (decl) = 0; else if (already_used) TREE_USED (decl) = 1; And, for u TREE_USED (type) is set. I'm afraid I have absolutely no idea how the fact whether type is used (comes from: #0 0x0000000000b1bf76 in maybe_record_typedef_use (t=<type_decl 0x7fffefc51000 U>) at ../../gcc/c-family/c-warn.c:1928 #1 0x000000000090ca8f in cp_parser_lookup_name (parser=0x7ffff7ff5bd0, name=<identifier_node 0x7fffefc3ea80 U>, tag_type=none_type, is_template=false, is_namespace=false, check_dependency=true, ambiguous_decls=0x7fffffffd418, name_location=299520) at ../../gcc/cp/parser.c:25718 #2 0x0000000000904ec9 in cp_parser_class_name (parser=0x7ffff7ff5bd0, typename_keyword_p=false, template_keyword_p=false, tag_type=none_type, check_dependency_p=true, class_head_p=false, is_declaration=false, enum_ok=false) at ../../gcc/cp/parser.c:21946 and then various copy_node) can affect whether a decl is used or not.