Using paragraphs 8.5.3p4 and p5 in the C++11 Standard, how do I prove that the snippet below doesn’t compile?

Firstly, a common mistake in reading 8.5.3p5 is to miss that it has two top level bullet points. You may have accidentally misread the final occurence of “Otherwise” as a third bullet point – but it is in fact a subpart of the second bullet point (also starting Otherwise).

char a="a";
char* p = &a;

OK

const char* & r = p;

So we have a lvalue-reference to cv1 T1 = pointer to const char being bound to an lvalue of type cv2 T2 = pointer to char

The two types are not reference-related or reference-compatible.

cv1 and cv2 are both empty.

The initializer expression does not have a class type

cv1 is not const.

Therefore, neither of the two bullet points in 8.5.3p5 apply, and the code is ill-formed.

The two bullet points are:

  1. If the reference is an lvalue reference and the initializer expression… [CONDITIONS FAIL TO APPLY]

  2. Otherwise, the reference shall be an lvalue reference to a non-volatile const type (i.e., cv1 shall be const [IT ISNT]), or the reference shall be an rvalue reference [IT ISNT].

Leave a Comment