This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/2502: function pointer with () arguments assumed to use varargs instead of void with -ansi



>Number:         2502
>Category:       c++
>Synopsis:       function pointer with () arguments assumed to use varargs instead of void with -ansi
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 06 08:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Peter Niemayer
>Release:        gcc-2.95.3
>Organization:
>Environment:
any (tested on Linux & HPUX)
>Description:
A function-pointer defined in a C header-file included with
'extern "C" { }' from a C++ source is assumed by the c++ 
compiler to take variable arguments "(...)" instead of
"(void)" as it should be according to ANSI-C - and that
even though "-ansi" was specified.

However, if "-ansi" _and_ "-pedantic" are both specified,
the source is accepted - but that is not the correct
behaviour as the gcc documentation clearly states:

-pedantic
 Issue  all  the warnings demanded by strict ANSI standard
 C; reject all programs that use forbidden extensions.

 Valid ANSI standard C programs should compile properly 
 with or without this option  (though  a rare few will
 require `-ansi').  However, without this option, certain
 GNU extensions and traditional C features are supported 
 as well.  With this option, they are rejected.  There is
 no reason to use this option; it exists only to satisfy
 pedants.

>How-To-Repeat:
Given these three little files: 

------ funcptr.h -------
typedef void (*bla) ();
------------------------

---- funcptr_user.h ---
extern "C" {
 #include "funcptr.h"
}

class foo {
public:

        void test(bla);

};
-----------------------

---- funcptr_user.cxx ---
#include "funcptr_user.h"

void test (void) {
        foo f;
        f.test(test);
}
-------------------------


> gcc -ansi -c funcptr_user.cxx
funcptr_user.cxx: In function `void test()':
funcptr_user.cxx:5: no matching function for call to `foo::test (void (&)())'
funcptr_user.h:9: candidates are: void foo::test(void (*)(...))

> gcc -ansi -pedantic -c funcptr_user.cxx
>
(succeeds)
>Fix:
None known, as both "-ansi" and "-pedantic" may break
many other nice things...
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]