g++ incorrectly picks method for va_list when given a char * parameter. Small file that shows the problem will be attached. When run, it shows that two methods from a class are selected, when only one should be considered. Have not verified if this is in the base gcc package. Reproducible: Always Steps to Reproduce: 1. g++ -o bug bug.cc 2. ./bug 3. Actual Results: Wrong output to stdio. Expected Results: Used the same class method for both calls. /* #include <inttypes.h> #include <sys/types.h> #include <sys/time.h> #include <cstring> #include <exception> #include <string> */ #include <cstdarg> #include <iostream> #define TIME_VAL timeval class Bug { public: static void Log(const bool to_stderr, const char *format, ...) __attribute__ ((format (printf, 2, 3))); static void Log(const bool to_stderr, const TIME_VAL &when, const char *format, ... ) __attribute__ ((format (printf, 3, 4))); static void Log(const bool to_stderr, const char *format, va_list arg ); static void Log(const bool to_stderr, const TIME_VAL &when, const char *format, va_list arg ); }; using namespace std; void Bug::Log(const bool to_stderr, const char *format, ...) { cerr << "called ..." << endl; } void Bug::Log(const bool to_stderr, const char *format, va_list arg) { cerr << "called va_list" << endl; } int main(const int, char *const *) { char buffer[32]; Bug::Log(false, "stuff %d\n", 1); Bug::Log(false, "stuff %s\n", buffer); return 0; }
3.4.1 does the same thing. Anyway, why do you think char* and va_list must be different types? As far as I know, there's nothing that disallows va_list basically being a typedef for some basic type, as long as the va_* macros/functions work correctly. Oh, and a simpler example to see how GCC handles it is simply #include <stdarg.h> int main() { va_list x="Hello!"; }
*** Bug 63116 has been marked as a duplicate of this bug. ***
I was asked to: Basically just repeating it's obvious won't convince anyone to whom it isn't obvious. Anyway, even if you don't want to explain why you feel this way, could you post a link to your bug report for GCC in your bug report for Gentoo? If you still can't post comments, I'll post it for you if you want. I'm not trying to convince anyone. But, this is the link: http://gcc.gnu.org/ml/gcc-bugs/2004-09/msg00538.html. Same info, except here I complied w/the request to trim headers.
(That was after a couple of e-mails because you had trouble posting a comment, for anyone reading this who didn't notice.) Have you reported it as a bug with GCC yet? I searched for va_list in their bugzilla, but nothing from you showed up. I did find a very similar bug though: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9942 It looks like the same thing in a slightly different situation to me. That was closed because it's not a defect (see the last comment there). By the way, from your last e-mail: "In C++, char* and va_list are not the same type, regardless of the base C type they resolve to." C and C++ are similar, but still different languages. Yes, it is possible to convert C++ code to C code, but GCC doesn't do this. C isn't relevant here. (My example happens to be simple enough that it compiles with GCC as C as well as C++.)
Not reported to gcc, which was aluded to in private email. What if it is in the Gentoo patches to gcc 3.3.4 20040623? I believed that it is the duty of Gentoo to first rule out that it is a problem with Gentoo changes before it is reported to gcc. However, I'm about ready to give up here, and take care of this myself. I would not like to receive a bug report for code that I did not write and know nothing about. Simple consideration.
Okay. I figured from the answer you got on the mailing list as well as the bug report I linked to that it also happened with GCC without Gentoo's patches, but if you want to be sure, I've now tested exactly your example: % g++ --version g++ (GCC) 3.4.2 Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. % g++ -o bug bug.cc % ./bug called ... called va_list % Which is exactly what happens with Gentoo's patches. Regardless of whether it's a bug, it's not caused by anything Gentoo added.
Good. I'll pursue it with gcc.
changing resolution to UPSTREAM
.