Topic: Array types and cv-qualifiers
Author: Nikolay Ivchenkov <tsoae@mail.ru>
Date: Thu, 7 Jan 2010 17:11:53 CST Raw View
I have read DR "Array types and cv-qualifiers":
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#112
But I still don't understand whether an array type can be cv-
qualified. Lets consider the following examples:
1) Is the program below well-formed?
template <class T>
struct is_const
{ static bool const value = false; };
template <class T>
struct is_const<T const>
{ static bool const value = true; };
template <class T>
void f(T &)
{ char checker[is_const<T>::value]; }
int const arr[1] = {};
int main()
{
f(arr);
}
2) Is the program below well-formed? Note: X().arr is rvalue of non-
class type (so, the rule "non-class rvalues always have cv-unqualified
types" (see 3.10/9) shall be applied).
struct A
{
A() {}
};
struct X
{
A const arr[1];
};
template <class T>
void f(T &) {}
int main()
{
f(X().arr);
}
3) Is the program below well-formed? Note: X().arr is rvalue of non-
class type. Comeau C++ does not reject this code.
#include <iostream>
struct A
{
A() {}
int f() { return i = 1000; }
int i;
};
struct X
{
A const arr[1];
};
int main()
{
std::cout << X().arr[0].f() << std::endl;
}
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]