public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 65323
@ 2015-03-06  8:37 Paolo Carlini
  2015-03-06 10:07 ` Paolo Carlini
  2015-03-11 20:26 ` Jason Merrill
  0 siblings, 2 replies; 5+ messages in thread
From: Paolo Carlini @ 2015-03-06  8:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 639 bytes --]

Hi,

this is a regression about duplicate warnings with 
-Wzero-as-null-pointer-constant. The regression is rather old, affects 
4_8-branch too, and started when check_default_argument got a 
perform_implicit_conversion_flags call which warns a first time, then 
maybe_warn_zero_as_null_pointer_constant as called by 
check_default_argument itself warns a second time. The latter call is 
even older, dates back to c++/52718, I think we can now safely remove it 
and keep on returning nullptr_node to avoid warning later still at the 
call sites (that was the point of c++/52718). Tested x86_64-linux.

Thanks,
Paolo.

///////////////////

[-- Attachment #2: patch_65323 --]
[-- Type: text/plain, Size: 633 bytes --]

Index: decl.c
===================================================================
--- decl.c	(revision 221230)
+++ decl.c	(working copy)
@@ -11227,11 +11227,9 @@ check_default_argument (tree decl, tree arg, tsubs
 				     LOOKUP_IMPLICIT);
   --cp_unevaluated_operand;
 
-  if (warn_zero_as_null_pointer_constant
-      && TYPE_PTR_OR_PTRMEM_P (decl_type)
+  if (TYPE_PTR_OR_PTRMEM_P (decl_type)
       && null_ptr_cst_p (arg)
-      && (complain & tf_warning)
-      && maybe_warn_zero_as_null_pointer_constant (arg, input_location))
+      && !NULLPTR_TYPE_P (TREE_TYPE (arg)))
     return nullptr_node;
 
   /* [dcl.fct.default]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++ Patch] PR 65323
  2015-03-06  8:37 [C++ Patch] PR 65323 Paolo Carlini
@ 2015-03-06 10:07 ` Paolo Carlini
  2015-03-11 20:26 ` Jason Merrill
  1 sibling, 0 replies; 5+ messages in thread
From: Paolo Carlini @ 2015-03-06 10:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 116 bytes --]

... in case, I think we can as well apply the below, a tad simpler. Also 
passes testing.

Paolo.

////////////////

[-- Attachment #2: patch_65323_2 --]
[-- Type: text/plain, Size: 620 bytes --]

Index: decl.c
===================================================================
--- decl.c	(revision 221230)
+++ decl.c	(working copy)
@@ -11227,11 +11227,8 @@ check_default_argument (tree decl, tree arg, tsubs
 				     LOOKUP_IMPLICIT);
   --cp_unevaluated_operand;
 
-  if (warn_zero_as_null_pointer_constant
-      && TYPE_PTR_OR_PTRMEM_P (decl_type)
-      && null_ptr_cst_p (arg)
-      && (complain & tf_warning)
-      && maybe_warn_zero_as_null_pointer_constant (arg, input_location))
+  if (TYPE_PTR_OR_PTRMEM_P (decl_type)
+      && null_ptr_cst_p (arg))
     return nullptr_node;
 
   /* [dcl.fct.default]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++ Patch] PR 65323
  2015-03-06  8:37 [C++ Patch] PR 65323 Paolo Carlini
  2015-03-06 10:07 ` Paolo Carlini
@ 2015-03-11 20:26 ` Jason Merrill
  2015-03-12 12:18   ` Paolo Carlini
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2015-03-11 20:26 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

On 03/06/2015 03:36 AM, Paolo Carlini wrote:
> this is a regression about duplicate warnings with
> -Wzero-as-null-pointer-constant. The regression is rather old, affects
> 4_8-branch too, and started when check_default_argument got a
> perform_implicit_conversion_flags call which warns a first time, then
> maybe_warn_zero_as_null_pointer_constant as called by
> check_default_argument itself warns a second time. The latter call is
> even older, dates back to c++/52718, I think we can now safely remove it
> and keep on returning nullptr_node to avoid warning later still at the
> call sites (that was the point of c++/52718). Tested x86_64-linux.

Do we need this special handling at all?  When I remove that whole 'if' 
block I still only get one warning from the 52718 testcase.

Jason


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++ Patch] PR 65323
  2015-03-11 20:26 ` Jason Merrill
@ 2015-03-12 12:18   ` Paolo Carlini
  2015-03-12 16:59     ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Carlini @ 2015-03-12 12:18 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

Hi,

On 03/11/2015 09:26 PM, Jason Merrill wrote:
> On 03/06/2015 03:36 AM, Paolo Carlini wrote:
>> this is a regression about duplicate warnings with
>> -Wzero-as-null-pointer-constant. The regression is rather old, affects
>> 4_8-branch too, and started when check_default_argument got a
>> perform_implicit_conversion_flags call which warns a first time, then
>> maybe_warn_zero_as_null_pointer_constant as called by
>> check_default_argument itself warns a second time. The latter call is
>> even older, dates back to c++/52718, I think we can now safely remove it
>> and keep on returning nullptr_node to avoid warning later still at the
>> call sites (that was the point of c++/52718). Tested x86_64-linux.
>
> Do we need this special handling at all?  When I remove that whole 
> 'if' block I still only get one warning from the 52718 testcase.
I just tried again for this reduced version of 52718 (I added a 0 && to 
the 'if'):

void* fun(void* a = 0);
void* f2 = fun();

and I got (removed the irrelevant carets):

52718_red.C:1:22: warning: zero as null pointer constant 
[-Wzero-as-null-pointer-constant]
  void* fun(void* a = 0);

52718_red.C:2:16: warning: zero as null pointer constant 
[-Wzero-as-null-pointer-constant]
  void* f2 = fun();

That is, as far as I can see, the rationale that led to an early 
*return* for 52718 still stand: no matter what we do at the beginning of 
check_default_argument, whether we warn via 
perform_implicit_conversion_flags or immediately, we still want to early 
return to avoid warning again at the call site.

Paolo.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++ Patch] PR 65323
  2015-03-12 12:18   ` Paolo Carlini
@ 2015-03-12 16:59     ` Jason Merrill
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2015-03-12 16:59 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

On 03/12/2015 06:13 AM, Paolo Carlini wrote:
> 52718_red.C:1:22: warning: zero as null pointer constant
> [-Wzero-as-null-pointer-constant]
>   void* fun(void* a = 0);
>
> 52718_red.C:2:16: warning: zero as null pointer constant
> [-Wzero-as-null-pointer-constant]
>   void* f2 = fun();

OK, then your second patch is OK.  But please add a comment that the 
code is there to avoid a redundant warning at the call site.

Jason


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-12 16:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-06  8:37 [C++ Patch] PR 65323 Paolo Carlini
2015-03-06 10:07 ` Paolo Carlini
2015-03-11 20:26 ` Jason Merrill
2015-03-12 12:18   ` Paolo Carlini
2015-03-12 16:59     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).