[Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function

gcc at dpinol dot com gcc-bugzilla@gcc.gnu.org
Tue Jul 15 09:08:00 GMT 2008


Hi,

When compiling the code below with 
gcc -c  -O2   -Wall main.cpp -I/opt/ACE_wrappers
, I get the warning 
/opt/ACE_wrappers/ace/Guard_T.inl:24: unexpected warning: guard 13936 owner may
be used uninitialized in this function

The warning refers to a guard's field, where the mutex passed in this line
  ACE_Write_Guard< MUTEX > guard (_mutex);

I've done a thousand tests but I have been unable to reproduce the warning
without using ACE. Even trimming the ACE headers made the warning to go away. 

What convinces me that the problem is in the compiler and not in ACE, or in my
code, is that removing some lines which have nothing to do with the mutex makes
the warning to disappear. Also commenting out the throw at the constructor
disables the warning

If you comment out any of these 3 lines, the warning disappears.
      c_pBufferStart( new int[ 10 ]),
      c_pBufferEnd( c_pBufferStart+10),
      m_pRead( (int*)c_pBufferStart ),

I can see the warning with both ACE 5.5 and latest ACE 5.6.5 available at
ftp://download.dre.vanderbilt.edu/previous_versions/ACE-src-5.6.5.tar.gz (only
9Mb)

I could also cut & paste the .ii file, but it's 38Kb

thanks

#include <ace/Thread_Mutex.h>
#include <ace/Guard_T.h>


      template<  class MUTEX = ACE_Thread_Mutex>
      class CircularBuffer
      {
         // Construction/Destruction
      public:
         CircularBuffer(MUTEX *mutex = NULL);

         unsigned long write( );

      protected:
         const int* c_pBufferStart;
         const int* c_pBufferEnd;
         int* m_pRead;
         MUTEX _nullMutex;
         MUTEX &_mutex;
      };


    template< class MUTEX >
      CircularBuffer<  MUTEX >::CircularBuffer(MUTEX *mutex):
      c_pBufferStart( new int[ 10 ]),
      c_pBufferEnd( c_pBufferStart+10),
      m_pRead( (int*)c_pBufferStart ),
      _mutex(mutex == NULL ? _nullMutex : *mutex)
    {
      if (mutex == NULL) throw "hjhk";
    }

    template< class MUTEX >
      unsigned long CircularBuffer<  MUTEX >::write( )
    {
       ACE_Write_Guard< MUTEX > guard (_mutex);
        return 0;
    }


      int main()
      {
         CircularBuffer<ACE_Thread_Mutex> buffer2;
         buffer2.write();
      }


-- 
           Summary: unexpected warning: guard 13936 owner may be used
                    uninitialized in this function
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at dpinol dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36833



More information about the Gcc-bugs mailing list