View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000427 | OpenFOAM | Bug | public | 2012-02-21 00:38 | 2012-08-13 10:55 |
Reporter | Assigned To | ||||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | resolved | Resolution | no change required | ||
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) 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...] | ||||
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? |
|
I cannot. |
|
Orphaned report - closing |
Date Modified | Username | Field | Change |
---|---|---|---|
2012-02-21 00:38 |
|
New Issue | |
2012-02-21 08:02 | henry | Note Added: 0001041 | |
2012-02-23 03:44 |
|
Note Added: 0001046 | |
2012-08-13 10:55 |
|
Note Added: 0001587 | |
2012-08-13 10:55 |
|
Status | new => resolved |
2012-08-13 10:55 |
|
Resolution | open => no change required |
2012-08-13 10:55 |
|
Assigned To | => user2 |