Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-1754

C++: indexing[] with implicit conversions from custom array to plain pointer is not parsed correctly

    XMLWordPrintableJSON

Details

    Description

      Consider

       

      template<class T, class allocatorT = MemoryPool::allocator>
       class local_array :...
      local_array<CMatrixRowPortrait> row;
      row[0].add_flux_portrait (fw_flux_port);
      

       

      The problem is that C++ parser does not recognize row indexing correctly because local_array does not have explicit indexing operator []. Indexing is performed via implicit conversion of local_array to plain pointer and applying the corresponding offset to this pointer:

        

        typedef const    T * CP_T;
           typedef          T * P_T;
          ///conversion to pointer type
           operator typename local_array<T>::CP_T       () const   {return m_ptr;}
           ///conversion to pointer type
           operator typename local_array<T>::P_T        ()         {return m_ptr;}
      

       

      This compiles OK with any modern compilers and works, but NetBeans C++ indexer does not understand this conversion. It does not recognize type of row[0] and so on.

      Temporary fix: explicit indexing operator

        

        /// Explicit [] operators (not necessary for building) with explicit pointers arithmetic help some code analysis tools to accept local_array and it's usage without complains.
           template <class IndexType>
           inline T& operator[](IndexType i)
           {
               return *( m_ptr + size_t( i ) );
           }
          /// Explicit [] operators (not necessary for building) with explicit pointers arithmetic help some code analysis tools to accept local_array and it's usage without complains.
           template <class IndexType>
           inline const T& operator[](IndexType i) const
           {
               return *( m_ptr + size_t( i ) );
           }
      

       

      With explicit operator[] NetBeans understands code correctly. It recognizes type of row[0] and so on.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            dyachenko.sergey Sergey Dyachenko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: