[Bug c++/60850] pedantic warning behavior when casting void* to ptr-to-func

tony at kelman dot net gcc-bugzilla@gcc.gnu.org
Mon Jul 28 16:38:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60850

--- Comment #9 from Tony Kelman <tony at kelman dot net> ---
Sure. In a configure.ac, (in this case using autoconf 2.59, not sure the most
recent version for which this applies) a macro like

AC_CHECK_DECL([rand],[AC_DEFINE([HAVE_RAND],[1],
                                [Define to 1 if function rand is
available])],,[
#ifdef HAVE_CSTDLIB
# include <cstdlib>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
])

expands into a probe that looks like this (plus the above includes)

int
main ()
{
#ifndef rand
  char *p = (char *) rand;
#endif

  ;
  return 0;
}

This compiles successfully (with a warning "ISO C++ forbids casting between
pointer-to-function and pointer-to-object [enabled by default]", but autoconf
cares more about the exit code) when -pedantic-errors is given with GCC 4.8.2,
and every other released GCC version I'm aware of, except that it errors with
4.8.3. The message with 4.8.3 is the same, but now it's an error and listed as
[-Werror=pedantic], and cc1plus reports "some warnings being treated as
errors."

The new behavior is arguably more correct, but has unfortunate consequences
with respect to backwards-compatibility.



More information about the Gcc-bugs mailing list