Patchwork [C++] PR 56130

login
register
mail settings
Submitter Paolo Carlini
Date Aug. 21, 2013, 1:45 p.m.
Message ID <5214C491.9000005@oracle.com>
Download mbox | patch
Permalink /patch/268808/
State New
Headers show

Comments

Paolo Carlini - Aug. 21, 2013, 1:45 p.m.
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.

Booted and tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
/cp
2013-08-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56130
	* semantics.c (finish_id_expression): Handle deprecated references.

/testsuite
2013-08-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56130
	* g++.dg/warn/deprecated-7.C: New.

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 201897)
+++ 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 = INDIRECT_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();
+}