c++ loosing const?
Philipp Thomas
pthomas@suse.de
Tue Apr 16 14:59:00 GMT 2002
This code
----------------------------------------------
template<class T>
class Link_array
{
public:
Link_array () {}
Link_array (Link_array<T> const &src) {}
// quicksort.
void sort (int (*compare) (T *const&,T *const&),
int lower = -1, int upper = -1);
};
class Note_column
{
public:
static int shift_compare (int *const &, int *const &) {};
};
class Collision // interface
{
public:
int automatic_shift ();
};
template<class T> void
Link_array<T>::sort (int (*compare) (T *const&,T *const&),
int lower, int upper)
{
int last = lower;
sort (compare, lower, last-1);
}
int
Collision::automatic_shift ()
{
int d = 1;
Link_array<int> clashes;
clashes.sort (Note_column::shift_compare);
return 1;
}
int main()
{
return 0;
}
----------------------------------------------
Results in:
gcc31_bug_const.cc: In member function `int Collision::automatic_shift()':
gcc31_bug_const.cc:38: invalid conversion from `int (*)(int* const&, int* const&)' to `int (*)(int*&, int*&)'
gcc31_bug_const.cc:38: initializing argument 1 of `void Link_array<T>::sort(int (*)(T*&, T*&), int, int) [with T = int]'
gcc31_bug_const.cc: In member function `void Link_array<T>::sort(int (*)(T*&, T*&), int, int) [with T = int]':
gcc31_bug_const.cc:38: instantiated from here
gcc31_bug_const.cc:29: invalid conversion from `int (*)(int* const&, int* const&)' to `int (*)(int*&, int*&)'
gcc31_bug_const.cc:29: initializing argument 1 of `void Link_array<T>::sort(int (*)(T*&, T*&), int, int) [with T = int]'
As far as I understand C++ (which isn't necessarily much), this is a bug in
gcc and not in the code. But before entering a possibly invalid PR, I'd like
to confirm that this is indeed a bug in gcc.
Philipp
--
Philipp Thomas <pthomas@suse.de>
SuSE Linux AG, Deutscherrnstr. 15-19, D-90429 Nuremberg, Germany
More information about the Gcc-bugs
mailing list