Topic: Cv-qualification of deduced template arguments
Author: hyrosen@mail.com (Hyman Rosen)
Date: Thu, 13 Feb 2003 00:10:59 +0000 (UTC) Raw View
Andrey Tarasevich wrote:
> I could not find a place in the standard that would give me a
> definitive answer.
3.9.3/2 says that cv-qualifiers applied to an array type
apply to the element type, not to the entire array.
Therefore, "a" has type "array of 10 const int". Unifying
this with "const T &" doesn't pull the "const" back out of
the element type, so T just becomes "array of 10 const int".
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: andreytarasevich@hotmail.com (Andrey Tarasevich)
Date: Wed, 12 Feb 2003 04:23:05 +0000 (UTC) Raw View
Hello
Consider the following code
template <typename T> void foo(const T&)
{
T a; // *
a[0] = 0; // **
}
int main()
{
const int a[10] = {};
foo(a);
}
Comeau reports an error at both line '*' ("const variable "a" requires
an initializer") and line '**' ("expression must be a modifiable
lvalue"). Apparently, Comeau deduces 'T' as 'const int[10]'. The same
applies to MSVC++ 6 (and 7, if I'm not mistaken).
GCC 3 compiles it without any problems, since 'T' is deduced as
'int[10]'.
Personally, I think GCC's deduction is more logical than Comeau's. But
I could not find a place in the standard that would give me a
definitive answer. Actually, all I could find in the standard seems to
support GCC's behavior and I couldn't find anything that would permit
Comeau's behavior. Am I missing something?
--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]