This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/24680] Invalid template code accepted
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Nov 2005 02:33:51 -0000
- Subject: [Bug c++/24680] Invalid template code accepted
- References: <bug-24680-8671@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #13 from pinskia at gcc dot gnu dot org 2005-11-05 02:33 -------
Ok, here is a real testcase which shows that EDG gets it really wrong:
#include <stdio.h>
void resize(double&)
{
printf("resize::double\n");
}
void resize(int&)
{
printf("resize::int\n");
}
template <typename T>
struct List
{
struct D { int size; };
D *d;
List &fill(const T &t, int size = -1);
};
template<>
struct List<int>::D
{
double size;
};
template <typename T>
List<T> &List<T>::fill(const T &t, int size)
{
resize(d->size);
return *this;
}
int main(void)
{
List<int> a;
a.fill(1, 1);
return 0;
}
-------
So you found a bug in EDG and not GCC.
The error which EDG front-end gives:
"ComeauTest.c", line 33: error: a reference of type "int &" (not
const-qualified)
cannot be initialized with a value of type "double"
resize(d->size);
^
detected during instantiation of
"List<T> &List<T>::fill(const T &, int) [with T=int]"
1 error detected in the compilation of "ComeauTest.c".
Which does not make sense at all since List<T>::D is type dependent and so is
d->size as shown above.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24680