View Issue Details

IDProjectCategoryView StatusLast Update
0000427OpenFOAM[All Projects] Bugpublic2012-08-13 10:55
Reporteruser357Assigned Touser2 
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionno change required 
Product Version 
Fixed in Version 
Summary0000427: Null reference is not defined behavior, but is used frequently in code involving Lists.
DescriptionThe null() static methods of various List types provide a null reference to that list, which is not a valid C++ operation as far as I know. The methods are implemented this way (e.g. from UListI.h)

    template<class T>
    inline const Foam::UList<T>& Foam::UList<T>::null()
    {
        return *reinterpret_cast< UList<T>* >(0);
    }

requiring dereferencing a null pointer.

Consider this quote from 8.3.2 of the C++ 98 standard:

    A reference shall be initialized to refer to a valid object or function. [Note: in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtained by dereferencing a null pointer, which causes undefined behavior...]
TagsNo tags attached.

Activities

henry

2012-02-21 08:02

manager   ~0001041

The way we create the null List is convenient and has efficiency advantages. Creating a null form of a List of every type would add significant complexity and compilation and linkage problems which would have to be handled carefully by everyone creating Lists of new types.

Can you provide an example of the current approach failing?

user357

2012-02-23 03:44

  ~0001046

I cannot.

user2

2012-08-13 10:55

  ~0001587

Orphaned report - closing

Issue History

Date Modified Username Field Change
2012-02-21 00:38 user357 New Issue
2012-02-21 08:02 henry Note Added: 0001041
2012-02-23 03:44 user357 Note Added: 0001046
2012-08-13 10:55 user2 Note Added: 0001587
2012-08-13 10:55 user2 Status new => resolved
2012-08-13 10:55 user2 Resolution open => no change required
2012-08-13 10:55 user2 Assigned To => user2