HP aC++/HP ANSI C A.06.28 Release (769149-001, March 2014)
{
RED, GREEN, BLUE
};
constexpr
This release of the compiler supports ‘constexpr’ under the C++11 compilation mode. The
"constexpr" feature allows functions and constructors that return constant values for constant
arguments, and variables whose initializers must be reduced to constants at the compile time.
Check N2235 and the additions in N3078, N3268, and N3277. In the following example, all
the constructors, conversion functions, and operator functions are folded at compile time to produce
a constant value for a3.
For example:
struct A {
int i;
constexpr A(int p) : i(p) {}
constexpr operator int() { return i; }
};
constexpr A operator+(A a1, A a2) {
return A{(int)a1 + (int)a2};
}
int main() {
constexpr A a1{1};
constexpr A a2{2};
constexpr A a3 = a1 + a2;
}
Nonstatic data member initializers
This release of the compiler supports ‘Nonstatic data member initializers’ as described by N2756
under the C++11 compilation mode. (NSDMIs) Nonstatic Data Member Initializers are initializers
on nonstatic data member declarations within the class.
For example:
struct A {
int i = 1;
A() {} // i gets initial value of 1
A(int p) : i(p) {} // i is initialized to p; NSDMI is not used
};
Unrestricted unions
This release of the compiler supports ‘unrestricted unions’ under the C++11 compilation mode. In
traditional C++, unions cannot contain fields with nontrivial construction, assignment, or destruction
semantics. However, C++11 does permit such fields but if so, the implicit default corresponding
constructor, destructor, or copy assignment operator of union is deleted, forcing a manual definition.
For example:
struct S { S(); };
union U {
S s; // Previously an error; now accepted in C++11 mode.
int i;
};
U u; // Error: The generated default constructor of U is deleted.
// forcing user to provide constructor for union U.
Delegating constructors
This release of the compiler supports ‘Delegate Constructors’ as described by N1986 under the
C++11 compilation mode. It allows one constructor to call another constructor of the same class
to do the initialization.
Improved support for C++11 core language features 11