Warning in CPP during IDE Build

Warning during QNX build:

I am using IDE 4.0.1 WINDOWS HOST

When I was trying with compilation in qnx environment, I use to get a warning like this:

In file included from …/source/sdk/source/port.cpp:168:

C:/QNX630/target/qnx6/usr/include/cpp/xlocale: In constructor `std::codecvt<_Elem, _Byte, _Statype>::codecvt(unsigned int) [with _Elem = char, _Byte = char, _Statype = _M

bstatet]’:

C:/QNX630/target/qnx6/usr/include/cpp/fstream:586: instantiated from here

C:/QNX630/target/qnx6/usr/include/cpp/xlocale:572: warning: declaration of _Refs' shadows a member of this’

How I can suppress the warning for that particular file?

Apart from suppressing Is there any way of resolving this warning?

Below is the code snippet from where the warning is coming up,

The code in port.cpp file:

aud_in_port::aud_in_port()

: m_flg_filemode ( false )

, m_rate ( AUD_PCM_RATE_16000 )

, m_numchans ( AUD_MONO )

, m_fmt ( AUD_PCM_FMT_16)

, m_audio_type ( AUD_PCM_ATYPE_SPEECH )

, state (ST_IDLE)

{ //line number 168

}

The aud_in_port class in aud_in_port.h, is given below:

class aud_in_port

{

protected:

        bool                                         m_flg_filemode;           

        std::ifstream                             m_filestream;

        size_t                                       m_frag_size;



        AUD_PCM_RATE_TYPE            m_rate;            

        AUD_PCM_CHANNELS             m_numchans;

        AUD_PCM_FORMAT                 m_fmt;

        AUD_PCM_AUDIO_TYPE          m_audio_type;

public:

        aud_in_port ();

        virtual ~aud_in_port();

        enum { ST_ERROR, ST_IDLE, ST_RUNNING} state;



        // stops reading from current port

        virtual bool   wait_for_available_fragment() = 0;

        virtual bool   read ( char* pbuf );

        virtual void   cancel () = 0;

        virtual void   stop ();

        virtual void   close ();

        virtual void   change_setup ( AUD_PCM_RATE_TYPE rate,      

                                                                    AUD_PCM_CHANNELS chans,

                                                                    AUD_PCM_FORMAT fmt,

                                                                    AUD_PCM_AUDIO_TYPE type );

        virtual bool   wait_init () = 0;                            // wait for device to be initialized

        

        

        size_t frag_size ();

        void set_frag_size(size_t size);



        bool set_filemode ( const char* filename );

};

Can anybody guide me in solving this issue.

Thanks in Advance,
Santha

Santha,

In your constructor you don’t have all your class variables in the initializer list. After:

m_flg_filemode(false)

should follow:

m_filestream() // Whatever initializer you want here
m_frag_size(0) // Ditto

So my guess is that the compiler is complaining because m_filestream (which is of type std::ifstream) isn’t being initialized in the proper order and hence is shadowed because the variables after it in the class are being initialized before it is.

Tim

Hello Tim,
Thanks for your reply.

Although i have passed the parameters to the constructor in proper order with the desired value, still i am getting the same warnings.
m_filestream(“myfile”)
m_frag_size(0)

Is there any other way of fixing this?

Regards,
Santha

Santha,

I would have thought that would solve it.

In the original post it complained about line 168 in port.cpp. Is it still complaining about that line and if so, which line in the code you posted is line 168.

This warning definitely is fixable.

Tim

Hi Tim,

Its still complaining for the same line. Although i have done some experiments (added code) as said by you still the compiler giving warning for a fixed line number i.e. 168

aud_in_port::aud_in_port()

: m_flg_filemode ( false )

, m_rate ( AUD_PCM_RATE_16000 )

, m_numchans ( AUD_MONO )

, m_fmt ( AUD_PCM_FMT_16)

, m_audio_type ( AUD_PCM_ATYPE_SPEECH )

, state (ST_IDLE)

{ //line number 168

}

One more thing:
The warning is due to inclusion of std::ifstream member in the aud_in_port. I think the one way to remove the warnings is by not using the file streams. We cannot modify the standard c++ stream library.
I think we may be able to disable the warning for that file specifically but I do not know how to do that with gnu gcc.
Could you please check its problem with the xlocale file.

Regards,
Santha

Santha,

I copied your aud_in_port class to a simple test program as follows:

#include <fstream.h>

using namespace std;

typedef int AUD_PCM_RATE_TYPE;
typedef int AUD_PCM_CHANNELS;
typedef int AUD_PCM_FORMAT;
typedef int AUD_PCM_AUDIO_TYPE;

int AUD_PCM_RATE_16000=1;
int AUD_MONO=2;
int AUD_PCM_FMT_16=3;
int AUD_PCM_ATYPE_SPEECH=4;

class aud_in_port 

{ 

protected: 

bool m_flg_filemode; 

std::ifstream m_filestream; 

size_t m_frag_size; 



AUD_PCM_RATE_TYPE m_rate; 

AUD_PCM_CHANNELS m_numchans; 

AUD_PCM_FORMAT m_fmt; 

AUD_PCM_AUDIO_TYPE m_audio_type; 



public: 

aud_in_port (); 

virtual ~aud_in_port(); 

enum { ST_ERROR, ST_IDLE, ST_RUNNING} state; 


// stops reading from current port 

virtual bool wait_for_available_fragment() = 0; 

virtual bool read ( char* pbuf ); 

virtual void cancel () = 0; 

virtual void stop (); 

virtual void close (); 

virtual void change_setup ( AUD_PCM_RATE_TYPE rate, 
AUD_PCM_CHANNELS chans, 
AUD_PCM_FORMAT fmt, 
AUD_PCM_AUDIO_TYPE type ); 

virtual bool wait_init () = 0; // wait for device to be initialized 


size_t frag_size (); 

void set_frag_size(size_t size); 


bool set_filemode ( const char* filename ); 

}; 


aud_in_port::aud_in_port() 

: m_flg_filemode ( false ) 
, m_filestream ( "foobar" )
, m_frag_size( 0 )
, m_rate ( AUD_PCM_RATE_16000 ) 
, m_numchans ( AUD_MONO ) 
, m_fmt ( AUD_PCM_FMT_16) 
, m_audio_type ( AUD_PCM_ATYPE_SPEECH ) 
, state (ST_IDLE) 

{ //line number 168 

} 

aud_in_port::~aud_in_port() 
{
}

bool aud_in_port::read(char *pbuf) 
{
	return true;
}
void aud_in_port::stop() 
{
}
void aud_in_port::close() 
{
}
void aud_in_port::change_setup(int rate, int channel, int format, int type) 
{
}
class bar : public aud_in_port
{
public:
   bar() ;
	 
private:
   bool wait_for_available_fragment()
   {
	   return true;
   }
   
   void cancel()
   {
   }
   
   bool wait_init()
   {
	   return false;
   }
   
   int test;
   int test1;
};

bar::bar() 

: aud_in_port()
, test ( 0 ) 
, test1 ( 0 ) 
{
};

int main() 
{
	bar foo;
	
}

and compiled it using gcc 2.9.5 and 3.3.5 with maximum warning levels enabled. I got no warnings at all.

This leads me to believe that the problem has moved to your derived classes (in my example it’s the bar class) since you fixed the problem in your aud_in_port class.

So I’d check all your derived classes. At least one (or more) of them has a problem in the constructor in terms of initializing things out of order.

Tim