+2003-05-19 Matt Austern <austern@apple.com>
+
+ * c-opts.c (COMMAND_LINE_OPTIONS): Add -Winvalid-offsetof option.
+ * c-common.h (warn_invalid_offsetof): Declare.
+ * c-common.c (warn_invalid_offsetof): Define.
+ * doc/invoke.texi: Document -Winvalid-offsetof.
+ * testsuite/g++.dg/other/offsetof3.C: New.
+ * testsuite/g++.dg/other/offsetof4.C: New.
+
2003-05-19 Kevin B. Hendricks <kevin.hendricks@sympatico.ca>
David Edelsohn <edelsohn@gnu.org>
int warn_abi = 0;
+/* Nonzero means warn about invalid uses of offsetof. */
+
+int warn_invalid_offsetof = 1;
+
/* Nonzero means warn about implicit declarations. */
int warn_implicit = 1;
extern int warn_abi;
+/* Nonzero means warn about invalid uses of offsetof. */
+
+extern int warn_invalid_offsetof;
+
/* Nonzero means warn about implicit declarations. */
extern int warn_implicit;
OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
OPT("Wimport", CL_ALL, OPT_Wimport) \
+ OPT("Winvalid-offsetof", CL_CXX, OPT_Winvalid_offsetof) \
OPT("Winvalid-pch", CL_ALL, OPT_Winvalid_pch) \
OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
OPT("Wmain", CL_C, OPT_Wmain) \
cpp_opts->warn_import = on;
break;
+ case OPT_Winvalid_offsetof:
+ warn_invalid_offsetof = on;
+ break;
+
case OPT_Winvalid_pch:
cpp_opts->warn_invalid_pch = on;
break;
+2003-05-19 Matt Austern <austern@apple.com>
+
+ * lang-options.h: Document -Wno-invalid-offsetof
+ * typeck.c (build_class_member_access_expr): Don't complain about
+ (Foo *)p->x for non-POD Foo if warn_invalid_offset is zero.
+
2003-05-18 Andrew Pinski <pinskia@physics.uc.edu>
* name-lookup.c (free_binding_entry): fix where the GTY markers are.
{ "-Wdeprecated", "" },
{ "-Wno-deprecated",
N_("Don't announce deprecation of compiler features") },
+ { "-Winvalid-offsetof", "" },
+ { "-Wno-invalid-offsetof",
+ N_("Don't warn about invalid uses of the offsetof macro") },
give the right answer. Note that we complain whether or not they
actually used the offsetof macro, since there's no way to know at this
point. So we just give a warning, instead of a pedwarn. */
- if (null_object_p && CLASSTYPE_NON_POD_P (object_type))
+ if (null_object_p && warn_invalid_offsetof
+ && CLASSTYPE_NON_POD_P (object_type))
{
warning ("invalid access to non-static data member `%D' of NULL object",
member);
-Wimplicit-function-declaration @gol
-Werror-implicit-function-declaration @gol
-Wimport -Winline -Winvalid-pch -Wno-endif-labels @gol
+-Wno-invalid-offsetof @gol
-Wlarger-than-@var{len} -Wlong-long @gol
-Wmain -Wmissing-braces @gol
-Wmissing-format-attribute -Wmissing-noreturn @gol
@opindex Winline
Warn if a function can not be inlined and it was declared as inline.
+@item -Wno-invalid-offsetof @r{(C++ only)}
+@opindex Wno-invalid-offsetof
+Suppress warnings from applying the @samp{offsetof} macro to a non-POD
+type. According to the 1998 ISO C++ standard, applying @samp{offsetof}
+to a non-POD type is undefined. In existing C++ implementations,
+however, @samp{offsetof} typically gives meaningful results even when
+applied to certain kinds of non-POD types. (Such as a simple
+@samp{struct} that fails to be a POD type only by virtue of having a
+constructor.) This flag is for users who are aware that they are
+writing nonportable code and who have deliberately chosen to ignore the
+warning about it.
+
+The restrictions on @samp{offsetof} may be relaxed in a future version
+of the C++ standard.
+
@item -Winvalid-pch
@opindex Winvalid-pch
Warn if a precompiled header (@pxref{Precompiled Headers}) is found in
--- /dev/null
+/* Verify that offsetof warns if given a non-POD */
+/* Copyright (C) 2003 Free Software Foundation, Inc. */
+/* Contributed by Matt Austern <austern@apple.com> 15 May 2003 */
+/* { dg-do compile } */
+
+struct X
+{
+ X() : x(3), y(4) { }
+ int x, y;
+};
+
+typedef X* pX;
+
+int yoff = int(&(pX(0)->y)); /* { dg-warning "invalid access" "" } */
+/* { dg-warning "macro was used incorrectly" "" { target *-*-* } 14 } */
--- /dev/null
+/* Verify that -Wno-invalid-offsetof disables warning */
+/* Copyright (C) 2003 Free Software Foundation, Inc. */
+/* Contributed by Matt Austern <austern@apple.com> 15 May 2003 */
+/* { dg-do compile } */
+/* { dg-options "-Wno-invalid-offsetof" } */
+
+struct X
+{
+ X() : x(3), y(4) { }
+ int x, y;
+};
+
+typedef X* pX;
+
+int yoff = int(&(pX(0)->y));