You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by "Sergey Dyachenko (JIRA)" <ji...@apache.org> on 2018/11/27 08:03:00 UTC

[jira] [Updated] (NETBEANS-1754) C++: indexing[] with implicit conversions from custom array to plain pointer is not parsed correctly

     [ https://issues.apache.org/jira/browse/NETBEANS-1754?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Dyachenko updated NETBEANS-1754:
---------------------------------------
    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.}}

 

  was:
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.}}

 


> C++: indexing[] with implicit conversions from custom array to plain pointer is not parsed correctly
> ----------------------------------------------------------------------------------------------------
>
>                 Key: NETBEANS-1754
>                 URL: https://issues.apache.org/jira/browse/NETBEANS-1754
>             Project: NetBeans
>          Issue Type: Bug
>          Components: cnd - Code Model, cnd - Navigation, cnd - Other
>    Affects Versions: 8.2
>            Reporter: Sergey Dyachenko
>            Priority: Major
>
> 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.}}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists