HP-UX Cadvise Diagnostics Reference Guide (5900-1865, August 2012)

Table Of Contents
Reference:
2830 %n has no corresponding operator delete%s (to be called if an
exception is thrown during initialization of an allocated object)
Cause:
For operator new, a corresponding operator delete needs to be provided so that it can be called
for proper destruction in case an exception is thrown during the initialization of the allocated
object.
Example:
void* operator new(unsigned long, void*) { return 0; }
struct Pool {
Pool() { }
} object;
Pool* allocate() { return new (&object) Pool(); }
Action:
Provide a corresponding operator delete to be called if an exception is thrown during the
initialization of the allocated object.
Reference:
2836 returning reference to local variable
Cause:
It is incorrect to return a reference to a local variable as the return value from a function. This is
because the lifetime of a local variable ends once the function returns.
Example:
int& foo() {
int i = 10;
return i;
}
Action:
Do not return reference to a local variable; if you really want to return a reference, make the local
variable static. This is because the lifetime of a static variable is same as lifetime of the program.
Reference:
2837 omission of explicit type is nonstandard ("int" assumed)
Cause:
A declaration or a definition does not have an explicit type, int will be assumed as the type but
this behavior is non-standard.
Example:
extern i;
a();
b(){}
extern c();
extern d(){}
Action:
Add an explicit type for the declaration or definition.
Reference:
C99 6.7.2(2), ANSI/ISO C++ 7.1.5(2)
2830 %n has no corresponding operator delete%s (to be called if an exception is thrown during initialization of an allocated
object)
47