===================================================================
@@ -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)
===================================================================
@@ -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" }
}
===================================================================
@@ -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];