News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Compiler warning during compiling wxSmith

Started by BlueHazzard, May 26, 2019, 02:00:18 AM

Previous topic - Next topic

BlueHazzard

Hi, this probably is not the right place to ask, but anyway:
I compile wxSmith and get this warning:
\src\plugins\contrib\wxSmith\wxwidgets\wxsitem.cpp: In member function 'void wxsItem::Codef(const wxString&, ...)':
\src\plugins\contrib\wxSmith\wxwidgets\wxsitem.cpp:525:29: warning: second parameter of 'va_start' not last named argument [-Wvarargs]

for function:
void wxsItem::Codef(const wxString &Fmt,...)
{
    if ( !GetCoderContext() )
    {
        // TODO: Debug log
        return;
    }
    va_list ap;
    va_start(ap,Fmt.c_str());
    Codef(GetCoderContext(),Fmt,GetCoderContext()->m_BuildingCode,ap);
    va_end(ap);
}


now i read the documentation:
Quote
void va_start (va_list ap, paramN);

paramN
    Name of the last named parameter in the function definition. The arguments extracted by subsequent calls to va_arg are those after paramN.

So va_start(ap,Fmt.c_str()); should actually be va_start(ap,Fmt);
but there is a warning in the documentation:
QuoteThe parameter shall not be of a reference type, or of a type that is not compatible with the type that results when passing an argument for which there is no parameter.
or
QuoteIf parm_n is declared with reference type or with a type not compatible with the type that results from default argument promotions, the behavior is undefined.
So i can not use a reference here? I have tested it and it seems to work at least with gcc5, but i do not like this "undefined"....

oBFusCATed

See how wxString::Format is implemented and what type it uses.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

BlueHazzard

As far as i can see they use some fancy template magic...
I will look if it is worth to replace the actual code with variadic templates, but i do not think it is worth... On GCC it works, on MSVC (or how it is called...) it won't work, but we do not compile codelocks with MSVC so there should not be a problem...

oBFusCATed

wx is c++<11, so I doubt the use variadic templates.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

BlueHazzard