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.carl...@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.

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)
     {

Reply via email to