Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Array types and cv-qualifiers

5 views
Skip to first unread message

Nikolay Ivchenkov

unread,
Jan 7, 2010, 6:11:53 PM1/7/10
to
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...@netlab.cs.rpi.edu<std-c%2B%2...@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

0 new messages