aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-02-15 19:17:03 -0500
committerJason Merrill <jason@redhat.com>2022-02-17 17:50:59 -0500
commit1b71bc7c8b18bd1b22debfde155f175fd1654942 (patch)
treea79add94015b8352a2fcddbc605812f382fff171
parent36100e0e952b92a6cd819620fcef851f0069ac8f (diff)
downloadgcc-1b71bc7c8b18bd1b22debfde155f175fd1654942.zip
gcc-1b71bc7c8b18bd1b22debfde155f175fd1654942.tar.gz
gcc-1b71bc7c8b18bd1b22debfde155f175fd1654942.tar.bz2
tree: tweak warn_deprecated_use
While looking at PR90451 I noticed that this function was failing to find the attributes if called with a variant of the struct. gcc/ChangeLog: * tree.cc (warn_deprecated_use): Look for TYPE_STUB_DECL on TYPE_MAIN_VARIANT. gcc/testsuite/ChangeLog: * g++.dg/warn/deprecated-16.C: New test.
-rw-r--r--gcc/testsuite/g++.dg/warn/deprecated-16.C2
-rw-r--r--gcc/tree.cc8
2 files changed, 7 insertions, 3 deletions
diff --git a/gcc/testsuite/g++.dg/warn/deprecated-16.C b/gcc/testsuite/g++.dg/warn/deprecated-16.C
new file mode 100644
index 0000000..8d1f419
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/deprecated-16.C
@@ -0,0 +1,2 @@
+struct __attribute((deprecated ("foo"))) A { }; // { dg-message "declared" }
+void f(const A&) { } // { dg-warning "deprecated: foo" }
diff --git a/gcc/tree.cc b/gcc/tree.cc
index dd919ff..2bbef2d 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -12047,10 +12047,12 @@ warn_deprecated_use (tree node, tree attr)
attr = DECL_ATTRIBUTES (node);
else if (TYPE_P (node))
{
- tree decl = TYPE_STUB_DECL (node);
+ tree decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node));
if (decl)
- attr = lookup_attribute ("deprecated",
- TYPE_ATTRIBUTES (TREE_TYPE (decl)));
+ {
+ node = TREE_TYPE (decl);
+ attr = TYPE_ATTRIBUTES (node);
+ }
}
}