Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type should std::remove_cv produce on an array of const T?

What type should std::remove_cv<const int[3]> produce? int[3] or const int[3]?

const int[3] is an array of 3 const int right?, and has no top-level cv-qualifier. So shouldn't it produce const int[3]? Latest version of gcc/libstdc++ is producing int[3] I think. Is this a bug? Why / why not?

like image 794
Andrew Tomazos Avatar asked Jan 04 '15 20:01

Andrew Tomazos


1 Answers

N4140 §3.9.3 [basic.type.qualifier]/p5, emphasis mine:

Cv-qualifiers applied to an array type attach to the underlying element type, so the notation “cv T,” where T is an array type, refers to an array whose elements are so-qualified. An array type whose elements are cv-qualified is also considered to have the same cv-qualifications as its elements. [ Example:

typedef char CA[5];
typedef const char CC;
CC arr1[5] = { 0 };
const CA arr2 = { 0 };

The type of both arr1 and arr2 is “array of 5 const char,” and the array type is considered to be const-qualified. —end example ]

See also CWG issue 1059.

like image 63
T.C. Avatar answered Sep 22 '22 19:09

T.C.