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.

/////////////////
/c-family
2012-08-04  Paolo Carlini  <paolo.carl...@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.carl...@oracle.com>

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

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];

Reply via email to