View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0000427||OpenFOAM||[All Projects] Bug||public||2012-02-21 00:38||2012-08-13 10:55|
|Priority||normal||Severity||minor||Reproducibility||have not tried|
|Status||resolved||Resolution||no change required|
|Fixed in Version|
|Summary||0000427: Null reference is not defined behavior, but is used frequently in code involving Lists.|
|Description||The 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)|
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...]
|Tags||No tags attached.|
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?
|Orphaned report - closing|
|2012-02-21 08:02||henry||Note Added: 0001041|
||Note Added: 0001046|
||Note Added: 0001587|
||Status||new => resolved|
||Resolution||open => no change required|
||Assigned To||=> user2|