Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 63112 - g++ 3.3.4-r1 picks wrong method, confusing char* and va_list
Summary: g++ 3.3.4-r1 picks wrong method, confusing char* and va_list
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: x86 Linux
: High critical (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
: 63116 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-09-07 04:33 UTC by George Garvey
Modified: 2004-09-13 11:50 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description George Garvey 2004-09-07 04:33:14 UTC
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;
}
Comment 1 Harald van Dijk (RETIRED) gentoo-dev 2004-09-07 05:20:43 UTC
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!"; }
Comment 2 Rainer Größlinger (RETIRED) gentoo-dev 2004-09-07 05:28:58 UTC
*** Bug 63116 has been marked as a duplicate of this bug. ***
Comment 3 George Garvey 2004-09-12 09:08:02 UTC
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.
Comment 4 Harald van Dijk (RETIRED) gentoo-dev 2004-09-12 23:38:12 UTC
(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++.)
Comment 5 George Garvey 2004-09-13 01:43:27 UTC
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.
Comment 6 Harald van Dijk (RETIRED) gentoo-dev 2004-09-13 02:45:51 UTC
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.
Comment 7 George Garvey 2004-09-13 02:47:56 UTC
Good. I'll pursue it with gcc.
Comment 8 solar (RETIRED) gentoo-dev 2004-09-13 11:25:11 UTC
changing resolution to UPSTREAM
Comment 9 solar (RETIRED) gentoo-dev 2004-09-13 11:50:17 UTC
.