[C++] PR 34927

Submitted by Paolo Carlini on Oct. 7, 2011, 11:56 p.m.

Details

Message ID 4E8F91A0.2030600@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 7, 2011, 11:56 p.m.
Hi,

this diagnostic PR is about duplicate inform messages for this kind of 
testcase, where C has a cloned destructor:

class A {};

struct C : A
{
   virtual ~C () = 0;
} c;

The fix seems easy: output a cloned destructor only once (+ output any 
other member functions normally). Patch tested x86_64-linux for regressions.

Ok?

Thanks,
Paolo.

///////////////////////
2011-10-07  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/34927
	* typeck2.c (abstract_virtuals_error_sfinae): Don't produce duplicate
	inform messages in case of cloned destructor.

Comments

Jason Merrill Oct. 8, 2011, 10:12 a.m.
On 10/08/2011 12:56 AM, Paolo Carlini wrote:
> The fix seems easy: output a cloned destructor only once (+ output any
> other member functions normally).

> +	  static bool done_cloned_dest = false;

This seems like it will only complain once per translation unit about 
virtual destructors.  How about instead of this flag, we look at which 
variant it is and only complain about one of them, perhaps the base?

Jason
Paolo Carlini Oct. 8, 2011, 10:32 a.m.
Hi,

> This seems like it will only complain once per translation unit about virtual destructors.

Oops, sorry, but this specific issue could be solved rather easily by not using a static, right?

>  How about instead of this flag, we look at which variant it is and only complain about one of them, perhaps the base?

Yes, isn't simply not using a static a rather straightforward alternative?

Paolo
Paolo Carlini Oct. 8, 2011, 10:59 a.m.
> Yes, isn't simply not using a static a rather straightforward alternative?

Ok, now I see: since it's easy, better avoid using *any* sort of flag, I'll do it.

Paolo

Patch hide | download patch | download mbox

Index: typeck2.c
===================================================================
--- typeck2.c	(revision 179660)
+++ typeck2.c	(working copy)
@@ -340,7 +340,17 @@  abstract_virtuals_error_sfinae (tree decl, tree ty
 	      type);
 
       FOR_EACH_VEC_ELT (tree, pure, ix, fn)
-	inform (input_location, "\t%+#D", fn);
+	{
+	  static bool done_cloned_dest = false;
+
+	  bool is_cloned_dest = DECL_CLONED_FUNCTION_P (fn);
+	  if (! is_cloned_dest || ! done_cloned_dest)
+	    inform (input_location, "\t%+#D", fn);
+
+	  if (is_cloned_dest)
+	    done_cloned_dest = true;
+	}
+
       /* Now truncate the vector.  This leaves it non-null, so we know
 	 there are pure virtuals, but empty so we don't list them out
 	 again.  */