public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 54161
@ 2012-08-04 12:46 Paolo Carlini
  2012-08-05 23:29 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2012-08-04 12:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi,

as discussed on the audit trail, I'm changing c_sizeof_or_alignof_type 
to unconditionally pedwarn in C++ mode. I have to also tweak an existing 
testcase, which was exactly relying on the warning to be suppressed by 
-Wno-pointer-arith.

Booted and tested x86_64-linux.

Thanks,
Paolo.

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

[-- Attachment #2: CL_54161 --]
[-- Type: text/plain, Size: 370 bytes --]

/c-family
2012-08-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54161
	* c-common.c (c_sizeof_or_alignof_type): In C++, pedwarn for function
	type and void type without -pedantic and -Wpointer-arith too.

/testsuite
2012-08-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54161
	* g++.dg/warn/pr54161.C: New.
	* g++.old-deja/g++.jason/ambig2.C: Adjust.


[-- Attachment #3: patch_54161 --]
[-- Type: text/plain, Size: 3093 bytes --]

Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c	(revision 190141)
+++ c-family/c-common.c	(working copy)
@@ -4578,10 +4578,17 @@ c_sizeof_or_alignof_type (location_t loc,
     {
       if (is_sizeof)
 	{
-	  if (complain && (pedantic || warn_pointer_arith))
-	    pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith,
-		     "invalid application of %<sizeof%> to a function type");
-          else if (!complain)
+	  if (complain)
+	    {
+	      if (c_dialect_cxx ())
+		pedwarn (loc, 0, "invalid application of %<sizeof%> to "
+			 "a function type");
+	      else if (pedantic || warn_pointer_arith)
+		pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith,
+			 "invalid application of %<sizeof%> to "
+			 "a function type");
+	    }
+          else
             return error_mark_node;
 	  value = size_one_node;
 	}
@@ -4601,12 +4608,17 @@ c_sizeof_or_alignof_type (location_t loc,
     }
   else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
     {
-      if (type_code == VOID_TYPE
-	  && complain && (pedantic || warn_pointer_arith))
-	pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith,
-		 "invalid application of %qs to a void type", op_name);
+      if (complain && type_code == VOID_TYPE)
+	{
+	  if (c_dialect_cxx ())
+	    pedwarn (loc, 0,
+		     "invalid application of %qs to a void type", op_name);
+	  else if (pedantic || warn_pointer_arith)
+	    pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith,
+		     "invalid application of %qs to a void type", op_name);
+	}
       else if (!complain)
-        return error_mark_node;
+	return error_mark_node;
       value = size_one_node;
     }
   else if (!COMPLETE_TYPE_P (type)
Index: testsuite/g++.old-deja/g++.jason/ambig2.C
===================================================================
--- testsuite/g++.old-deja/g++.jason/ambig2.C	(revision 190141)
+++ testsuite/g++.old-deja/g++.jason/ambig2.C	(working copy)
@@ -2,10 +2,8 @@
 // { dg-options "-Wno-pointer-arith" }
 // Testcase for ambiguity between cast and parmlist.
 // This ambiguity accounts for 1 of the r/r conflicts.
-// Do not compile with -pedantic so that the compiler will accept taking
-// the sizeof a function type.
 
 void f(){
   (void)sizeof(int((int)1.2));
-  (void)sizeof(int((int)));		// { dg-bogus "" } 
+  (void)sizeof(int((int)));		// { dg-warning "invalid application" } 
 }
Index: testsuite/g++.dg/warn/pr54161.C
===================================================================
--- testsuite/g++.dg/warn/pr54161.C	(revision 0)
+++ testsuite/g++.dg/warn/pr54161.C	(revision 0)
@@ -0,0 +1,12 @@
+// PR c++/54161
+// { dg-options "-Wno-pointer-arith" }
+
+void f();
+void (&g())();
+
+const int a = sizeof(void);    // { dg-warning "invalid application" }
+const int b = sizeof(void());  // { dg-warning "invalid application" }
+const int c = sizeof(f());     // { dg-warning "invalid application" }
+const int d = sizeof(g());     // { dg-warning "invalid application" }
+
+typedef char test[a + b + c + d > 0 ? 1 : -1];

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

* Re: [C++ Patch] PR 54161
  2012-08-04 12:46 [C++ Patch] PR 54161 Paolo Carlini
@ 2012-08-05 23:29 ` Jason Merrill
  2012-08-06  0:10   ` Paolo Carlini
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2012-08-05 23:29 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc-patches

On reflection, I think I prefer the status quo.  As long as the pedwarn 
is on by default, I don't mind letting people disable it with 
-Wno-pointer-arith.

Jason

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

* Re: [C++ Patch] PR 54161
  2012-08-05 23:29 ` Jason Merrill
@ 2012-08-06  0:10   ` Paolo Carlini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Carlini @ 2012-08-06  0:10 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On 08/06/2012 01:29 AM, Jason Merrill wrote:
> On reflection, I think I prefer the status quo.  As long as the 
> pedwarn is on by default, I don't mind letting people disable it with 
> -Wno-pointer-arith.
I hear you. Then, let's just close the PR.

Thanks!
Paolo.

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

end of thread, other threads:[~2012-08-06  0:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-04 12:46 [C++ Patch] PR 54161 Paolo Carlini
2012-08-05 23:29 ` Jason Merrill
2012-08-06  0:10   ` Paolo Carlini

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