Home > Archive > VC Language > June 2005 > Template Compiler Error (array/pointers)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Template Compiler Error (array/pointers)
|
|
| Mycroft Holmes 2005-05-30, 9:00 am |
| Hi. The following sample is fine for Comeau Compiler.
Howver VC7.1 does not compile line #2, but accepts line #1.
It looks like it-s trying to unnecessarily let "double [3][4]" decay into
"double (*)[4]" (or whatever)
For the moment we'll stick to the pointer workaround, but can anyone try
VC8.0 as well?
Thanks
MH
//////////////////////////////////////////////////////////////////////////
#include <cstddef>
using std::size_t;
template <typename matrix_t>
struct matrix_traits
{
typedef typename matrix_t::value_type value_type;
typedef matrix_t copy_type;
};
template <typename scalar_t, size_t R, size_t C>
struct matrix_traits< scalar_t [R][C] >
{
typedef scalar_t value_type;
typedef value_type copy_type[R][C];
};
template <typename matrix_t>
size_t FAKE_rank(const matrix_t& m, const typename
matrix_traits<matrix_t>::value_type epsilon = 0)
{
typedef matrix_traits<matrix_t> traits_t;
typedef typename traits_t::copy_type copy_t;
copy_t A;
copy_t B;
copy_t* C = (epsilon>0) ? (&A) : (&B); // LINE #1
copy_t& D = (epsilon>0) ? (A) : (B); // LINE #2
return 0;
}
int main(int argc, char* argv[])
{
double b[3][4];
FAKE_rank(b);
return 0;
}
| |
| Igor Tandetnik 2005-05-30, 4:01 pm |
| "Mycroft Holmes" <m.holmes@nospam.it> wrote in message
news:eZD9COQZFHA.1088@TK2MSFTNGP14.phx.gbl
> Hi. The following sample is fine for Comeau Compiler.
> Howver VC7.1 does not compile line #2, but accepts line #1.
> It looks like it-s trying to unnecessarily let "double [3][4]" decay
> into "double (*)[4]" (or whatever)
>
> For the moment we'll stick to the pointer workaround, but can anyone
> try VC8.0 as well?
Looks like a bug, and it still produces an error with VC8 Beta 2:
..\Test.cpp(36) : error C2440: 'initializing' : cannot convert from
'double (*)[4]' to 'copy_t (&)'
.\Test.cpp(46) : see reference to function template
instantiation 'size_t FAKE_rank<double[3][4]>(const matrix_t (&),const
double)' being compiled
with
[
matrix_t=double [3][4]
]
Consider reporting it at http://lab.msdn.microsoft.com/productfeedback/
.. If you do, post a link here, I'll validate it.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
| |
| Mycroft Holmes 2005-05-30, 4:01 pm |
| ----- Original Message -----
>
> Looks like a bug, and it still produces an error with VC8 Beta 2:
> . If you do, post a link here, I'll validate it.
thanks for the reply.
this should do:
http://lab.msdn.microsoft.com/Produ...ackId=FDBK28317
| |
| Tom Widmer 2005-06-01, 9:09 am |
| Mycroft Holmes wrote:
> Hi. The following sample is fine for Comeau Compiler.
> Howver VC7.1 does not compile line #2, but accepts line #1.
> It looks like it-s trying to unnecessarily let "double [3][4]" decay into
> "double (*)[4]" (or whatever)
>
> For the moment we'll stick to the pointer workaround, but can anyone try
> VC8.0 as well?
This simpler program exhibits the same bug:
int main()
{
double a[1];
double b[1];
double (&c)[1] = true ? a : b;
}
For some reason, it is doing an array-to-pointer conversion on the
result of the conditional expression. 5.16/4 makes it clear that this
shouldn't happen.
Tom
|
|
|
|
|