https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104627
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- 2022-02-28 Jakub Jelinek <ja...@redhat.com> PR c/104627 * tree.cc (warn_deprecated_use): For types prefer to use node and only use TYPE_MAIN_VARIANT (node) if TYPE_STUB_DECL (node) is NULL. --- gcc/tree.cc.jj 2022-02-18 12:38:06.172391744 +0100 +++ gcc/tree.cc 2022-02-28 13:17:57.223216010 +0100 @@ -12047,8 +12047,11 @@ warn_deprecated_use (tree node, tree att attr = DECL_ATTRIBUTES (node); else if (TYPE_P (node)) { - tree decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)); + tree decl = TYPE_STUB_DECL (node); if (decl) + attr = TYPE_ATTRIBUTES (TREE_TYPE (decl)); + else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node))) + != NULL_TREE) { node = TREE_TYPE (decl); attr = TYPE_ATTRIBUTES (node); keeps the previous C behavior for gcc.dg/deprecated.c and the #c5 testcase, while maintains the C++ behavior for deprecated-16.C and the #c5 testcase.