return 1;

}

Incorrect Syntax for Calls to operator new

In HP C++, you can use incorrect syntax to call operator new. In HP aC++, an error is generated when incorrect syntax for operator new is used. To change this, add parentheses around the use of operator new. This code compiles correctly with both HP C++ and HP aC++.

Example:

Compiling the following code on HP C++ does not generate a warning or an error. Compiling the code on HP aC++ generates errors stating operator expected instead of new and undeclared variable operator S.

struct S {int f();};

int g() { return new S->f();}

// int g() { return (new S)->f();} // This will fix the problem. int S:: f( ) { return 1;}

main() { return 1; }

Using :: in Class Definitions

In HP C++, you can declare members of classes inside the class using the following incorrect syntax:

class_name::member_name

In HP aC++, this incorrect syntax is considered an error. You must remove the class_name:: specification from the member definition.

Example:

Compiling the following code on HP C++ does not generate a warning or an error. Compiling the code on HP aC++ generates an error stating that you cannot qualify members of class X in the class definition.

class X{

int X::f();

// int f(); // This will fix the problem and

// run successfully on both compilers.

>

int main(){

}

Duplicate Formal Argument Names

In HP C++, duplicate formal argument names are allowed. In HP aC++, duplicate formal argument names generate an error. To avoid this, use unique formal parameter names.

Example:

The following code compiles with HP C++. With HP aC++, an error is generated stating that symbol aParameter has been redefined and where it was previously defined.

int a(int aParameter, int * aParameter);

Ambiguous Function or Object Declaration

In HP C++, an ambiguous function or object declaration compiles without warning, assuming an object declaration. In HP aC++, an ambiguous function or object declaration generates an error. To change this, change the code to remove the ambiguity.

Example:

struct

A

{A(int);};

struct

B

{B(const A &); void g();};

void

f(int p)

{

B

b(A(p));

// Declaration of function or object?

Migration Considerations Related to Standardization 215

Page 215
Image 215
HP C/aC++ for PA-RISC Software manual Incorrect Syntax for Calls to operator new, Using in Class Definitions