Hi again,
On 08/21/2013 03:45 PM, Paolo Carlini wrote:
Hi,
this bug points out that we fail to emit deprecated warnings when
references are involved. Turns out that at the end of
finish_id_expression the VAR_DECL is wrapped in INDIRECT_REF. The
trivial patch below appears to work fine and should be pretty safe in
terms of false positives, because the warning is enabled by default.
In fact, since we have an issue with *references* I think using
REFERENCES_REF_P, per the below, would be more correct. Lightly tested
so far, I'm booting and testing it.
Thanks again,
Paolo.
//////////////////////////
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 201902)
+++ cp/semantics.c (working copy)
@@ -3457,8 +3457,10 @@ finish_id_expression (tree id_expression,
}
}
- if (TREE_DEPRECATED (decl))
- warn_deprecated_use (decl, NULL_TREE);
+ /* Handle references (c++/56130). */
+ tree t = REFERENCE_REF_P (decl) ? TREE_OPERAND (decl, 0) : decl;
+ if (TREE_DEPRECATED (t))
+ warn_deprecated_use (t, NULL_TREE);
return decl;
}
Index: testsuite/g++.dg/warn/deprecated-7.C
===================================================================
--- testsuite/g++.dg/warn/deprecated-7.C (revision 0)
+++ testsuite/g++.dg/warn/deprecated-7.C (working copy)
@@ -0,0 +1,17 @@
+// PR c++/56130
+
+int g_nn;
+int& g_n __attribute__((deprecated)) = g_nn;
+
+void f()
+{
+ int f_nn;
+ int& f_n __attribute__((deprecated)) = f_nn;
+ f_n = 1; // { dg-warning "'f_n' is deprecated" }
+}
+
+int main()
+{
+ g_n = 1; // { dg-warning "'g_n' is deprecated" }
+ f();
+}