Patchwork [C++] PR 50660

login
register
mail settings
Submitter Paolo Carlini
Date Oct. 9, 2011, 12:13 p.m.
Message ID <4E918FED.4060002@oracle.com>
Download mbox | patch
Permalink /patch/118586/
State New
Headers show

Comments

Paolo Carlini - Oct. 9, 2011, 12:13 p.m.
Hi,

another duplicated diagnostic message. This one happens for snippets 
like the below due to the temporary for the const ref:

int g(const int&);
int m2()
{
return g(__null);
}

50660.C:4:18: warning: passing NULL to non-pointer argument 1 of ‘int 
g(const int&)’
50660.C:4:18: warning: passing NULL to non-pointer argument 1 of ‘int 
g(const int&)’

I'm changing conversion_null_warnings to return true when a warning is 
actually produced, which is checked by convert_like_real before calling 
again itself recursively. I think it should be safe to shut down in that 
case all kinds of further warnings, otherwise, we could even envisage 
adding an issue_conversion_null_warnings parameter to convert_like_real, 
as a last resort which certainly works.

Patch tested x86_64-linux.

Thanks,
Paolo.

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

	PR c++/50660
	* call.c (conversion_null_warnings): Return true when a warning
	is actually emitted.
	(convert_like_real): When conversion_null_warnings returns true
	set issue_conversion_warnings to false.
Jason Merrill - Oct. 9, 2011, 10:40 p.m.
Hmm, I guess it's unlikely that a conversion is going to hit both that 
warning and another one.  OK.

Jason
Jason Merrill - Oct. 9, 2011, 10:41 p.m.
On 10/09/2011 11:40 PM, Jason Merrill wrote:
> Hmm, I guess it's unlikely that a conversion is going to hit both that
> warning and another one. OK.

Wait...how about changing conversion_null_warnings to stop looking 
through references?  Does that break anything?

Jason
Paolo Carlini - Oct. 9, 2011, 10:55 p.m.
On 10/10/2011 12:41 AM, Jason Merrill wrote:
> On 10/09/2011 11:40 PM, Jason Merrill wrote:
>> Hmm, I guess it's unlikely that a conversion is going to hit both that
>> warning and another one. OK.
> Wait...how about changing conversion_null_warnings to stop looking 
> through references?  Does that break anything?
Let me check...

Paolo.
Paolo Carlini - Oct. 9, 2011, 11:44 p.m.
On 10/10/2011 12:41 AM, Jason Merrill wrote:
> On 10/09/2011 11:40 PM, Jason Merrill wrote:
>> Hmm, I guess it's unlikely that a conversion is going to hit both that
>> warning and another one. OK.
>
> Wait...how about changing conversion_null_warnings to stop looking 
> through references?  Does that break anything?
If I just do this (I hope it's what you had in mind):

  static void
  conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
  {
-  tree t = non_reference (totype);
+  tree t = totype; /*non_reference (totype); */

I see this failure, for sure: cpp0x/variadic111.C, that is:

// PR c++/48424
// { dg-options -std=c++0x }

template<typename... Args1>
struct S
{
   template<typename... Args2>
     void f(Args1... args1, Args2&&... args2)
     {
     }
};

int main()
{
   S<int, double> s;
   s.f(1,2.0,false,'a');
}

triggers:

variadic111.C:16:22: warning: converting ‘false’ to pointer type for 
argument 3 of ‘void S<Args1>::f(Args1 ..., Args2&& ...) [with Args2 = 
{bool, char}; Args1 = {int, double}]’ [-Wconversion-null]

Also, tree-ssa/copyprop.C, for example.

Paolo.
Jason Merrill - Oct. 10, 2011, 11:46 p.m.
On 10/10/2011 12:44 AM, Paolo Carlini wrote:
> If I just do this (I hope it's what you had in mind):
>
> - tree t = non_reference (totype);
> + tree t = totype; /*non_reference (totype); */
>
> variadic111.C:16:22: warning: converting ‘false’ to pointer type for
> argument 3 of ‘void S<Args1>::f(Args1 ..., Args2&& ...) [with Args2 =
> {bool, char}; Args1 = {int, double}]’ [-Wconversion-null]

Hmm, need to also change POINTER_TYPE_P to TYPE_PTR_P.

Jason

Patch

Index: call.c
===================================================================
--- call.c	(revision 179720)
+++ call.c	(working copy)
@@ -5509,9 +5509,9 @@  build_temp (tree expr, tree type, int flags,
 
 /* Perform warnings about peculiar, but valid, conversions from/to NULL.
    EXPR is implicitly converted to type TOTYPE.
-   FN and ARGNUM are used for diagnostics.  */
+   FN and ARGNUM are used for diagnostics.  Returns true if warned.  */
 
-static void
+static bool
 conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
 {
   tree t = non_reference (totype);
@@ -5526,6 +5526,7 @@  conversion_null_warnings (tree totype, tree expr,
       else
 	warning_at (input_location, OPT_Wconversion_null,
 		    "converting to non-pointer type %qT from NULL", t);
+      return true;
     }
 
   /* Issue warnings if "false" is converted to a NULL pointer */
@@ -5538,7 +5539,9 @@  conversion_null_warnings (tree totype, tree expr,
       else
 	warning_at (input_location, OPT_Wconversion_null,
 		    "converting %<false%> to pointer type %qT", t);
+      return true;
     }
+  return false;
 }
 
 /* Perform the conversions in CONVS on the expression EXPR.  FN and
@@ -5624,8 +5627,9 @@  convert_like_real (conversion *convs, tree expr, t
       return cp_convert (totype, expr);
     }
 
-  if (issue_conversion_warnings && (complain & tf_warning))
-    conversion_null_warnings (totype, expr, fn, argnum);
+  if (issue_conversion_warnings && (complain & tf_warning)
+      && conversion_null_warnings (totype, expr, fn, argnum))
+    issue_conversion_warnings = false;
 
   switch (convs->kind)
     {