I recently found out that the types of parameters in a non-defining function declaration may be of incomplete types. This is very exciting.
class A;
class B {
B(A a); // Legal! Wow!
};
The type is required to be complete only for the definition:
B::B(A a) {}; // error: ‘a’ has incomplete type
I’ve been trying to pin down the legalese for this, but my searches through C++11 for “[in]complete type” have yielded nothing of much interest, leading me to assume that these semantics are defined through an enigmatic maze of constructions.
Can you help me pin down the standard text that defines the above requirements for the types of function parameters being complete or otherwise, in function declarations vs definitions?
(9.2/10 and 9.4.2/2 give us the requirements for static data member declarations and non-static data member definitions in class definitions.)
Function declaration
There doesn’t appear to be anything directly addressing this. It may be that it’s allowed because it is not disallowed.
7.1.1/9tells us that it’s ok for anexterndeclaration (which is semantically similar to a member function declaration), and shows us non-normatively that types in such declarations may be incomplete:Function definition (thanks litb)
Function call