libkdtree++-dev does not compile with g++-4.0

Bug #105040 reported by pablodiazgutierrez
12
Affects Status Importance Assigned to Milestone
Ubuntu
Fix Released
Undecided
Unassigned
Nominated for Intrepid by Yani Ioannou

Bug Description

Binary package hint: libkdtree++-dev

libkdtree++-dev produces compilation erros with recent versions of g++, like 4.0. Version 3.4 works fine, though. Here is my compiler output:

g++ -c -Wall -Wno-deprecated -g -DDEBUG -Iinclude -I/usr/include/GL//include -I/usr/include/GL/ src/main.cpp -o obj/debug/main.o
/usr/include/kdtree++/kdtree.hpp:36: error: ‘KDTree’ is not a type
/usr/include/kdtree++/kdtree.hpp:36: error: expected ‘,’ or ‘...’ before ‘<’ token
/usr/include/kdtree++/kdtree.hpp: In function ‘std::ostream& KDTree::operator<<(std::ostream&, int)’:
/usr/include/kdtree++/kdtree.hpp:38: error: ‘__T’ was not declared in this scope
/usr/include/kdtree++/kdtree.hpp:46: error: expected initializer before ‘<’ token
/usr/include/kdtree++/kdtree.hpp:47: error: ‘_Tree’ has not been declared
/usr/include/kdtree++/kdtree.hpp:47: error: invalid type in declaration before ‘;’ token
/usr/include/kdtree++/kdtree.hpp:56: error: invalid type argument of ‘unary *’
/usr/include/kdtree++/kdtree.hpp:57: error: ‘_Tree’ has not been declared
/usr/include/kdtree++/kdtree.hpp:57: error: ‘_Tree’ has not been declared
/usr/include/kdtree++/kdtree.hpp:58: error: ‘_Tree’ has not been declared
/usr/include/kdtree++/kdtree.hpp:58: error: ‘_Tree’ has not been declared
/usr/include/kdtree++/kdtree.hpp: At global scope:
/usr/include/kdtree++/kdtree.hpp:75: error: declaration of ‘typedef typename KDTree::_Alloc_base<_Val, _Alloc>::allocator_type KDTree::KDTree<__K, _Val, _Acc, _Cmp, _Alloc>::allocator_type’
/usr/include/kdtree++/kdtree.hpp:73: error: conflicts with previous declaration ‘typedef _Alloc KDTree::KDTree<__K, _Val, _Acc, _Cmp, _Alloc>::allocator_type’
/usr/include/kdtree++/kdtree.hpp: In instantiation of ‘KDTree::KDTree<3u, IndexedPoint, KDTree::_Bracket_accessor<IndexedPoint>, std::less<float>, std::allocator<KDTree::_Node<IndexedPoint> > >’:
include/votingMachine.h:42: instantiated from here
/usr/include/kdtree++/kdtree.hpp:751: error: template-id ‘operator<< <>’ for ‘std::basic_ostream<char, std::char_traits<char> >& KDTree::operator<<(std::basic_ostream<char, std::char_traits<char> >&, const KDTree::KDTree<3u, IndexedPoint, KDTree::_Bracket_accessor<IndexedPoint>, std::less<float>, std::allocator<KDTree::_Node<IndexedPoint> > >&)’ does not match any template declaration

Revision history for this message
pablodiazgutierrez (pablo-ics) wrote :

I forgot to add this. The code that launches the errors is as simple as the following:

#include <stdlib.h>
#include <iostream>
#include <vector>
#include <set>
#include <kdtree++/kdtree.hpp>

Revision history for this message
LiraNuna (liranuna) wrote :

I can confirm the problem is happening here too.Only with GCC >4.0

Revision history for this message
pablodiazgutierrez (pablodiazgutierrez) wrote :

The bug is still standing. I found out that the author has released several upgrades that have not been added to Ubuntu: http://libkdtree.alioth.debian.org/

The current version is 0.6.2, but Gutsy has version 0.2.1-1!

Revision history for this message
pablodiazgutierrez (pablodiazgutierrez) wrote :

I have verified the bug in several systems, and also got positive review in the comments. Furthermore, the fix is so simple...

Changed in libkdtree++:
status: New → Confirmed
Revision history for this message
Bart Kroon (bart-kroon) wrote :

With:
- Ubuntu 8.04.1,
- gcc 4.2.3,
- libkdtree++-dev 0.2.1-1,

and this test one-liner:

#include <kdtree++/kdtree.hpp>

this is the compiler output:

$ g++ -Wall -Werror -pedantic test.cpp
In file included from test.cpp:1:
/usr/include/kdtree++/kdtree.hpp:75: error: declaration of ‘typedef typename KDTree::_Alloc_base<_Val, _Alloc>::allocator_type KDTree::KDTree<__K, _Val, _Acc, _Cmp, _Alloc>::allocator_type’
/usr/include/kdtree++/kdtree.hpp:73: error: conflicts with previous declaration ‘typedef _Alloc KDTree::KDTree<__K, _Val, _Acc, _Cmp, _Alloc>::allocator_type’

Checking the source code it is a simple mistake and the compiler error is justified:

66 template <size_t const __K, typename _Val,
67 typename _Acc = _Bracket_accessor<_Val>,
68 typename _Cmp = std::less<typename _Acc::subvalue_type>,
69 typename _Alloc = std::allocator<_Node<_Val> > >
70 class KDTree : protected _Alloc_base<_Val, _Alloc>
71 {
72 protected:
73 typedef _Alloc allocator_type;
74 typedef _Alloc_base<_Val, _Alloc> _Base;
75 typedef typename _Base::allocator_type allocator_type;

Removing line 73 is enough to fix the bug.

Revision history for this message
Bart Kroon (bart-kroon) wrote :

With:
 - Ubuntu 8.10 (development branch),
 - gcc 4.3.2,
 - libkdtree++-dev 0.6.2-1,

and the same one-liner:

$ g++ -Wall -Werror -pedantic test.cpp
In file included from /usr/include/kdtree++/kdtree.hpp:61,
                 from test.cpp:1:
/usr/include/kdtree++/allocator.hpp:21: error: declaration of ‘typedef struct KDTree::_Node<_Val> KDTree::_Alloc_base<_Tp, _Alloc>::_Node’
/usr/include/kdtree++/node.hpp:49: error: changes meaning of ‘_Node’ from ‘struct KDTree::_Node<_Val>’
In file included from test.cpp:1:
/usr/include/kdtree++/kdtree.hpp:90: error: declaration of ‘typedef class KDTree::_Node_compare<_Val, _Acc, _Cmp> KDTree::KDTree<__K, _Val, _Acc, _Cmp, _Alloc>::_Node_compare’
/usr/include/kdtree++/node.hpp:65: error: changes meaning of ‘_Node_compare’ from ‘class KDTree::_Node_compare<_Val, _Acc, _Cmp>’
/usr/include/kdtree++/kdtree.hpp:93: error: declaration of ‘typedef struct KDTree::_Region<__K, _Val, typename _Acc::result_type, _Acc, _Cmp> KDTree::KDTree<__K, _Val, _Acc, _Cmp, _Alloc>::_Region’
/usr/include/kdtree++/region.hpp:20: error: changes meaning of ‘_Region’ from ‘struct KDTree::_Region<__K, _Val, typename _Acc::result_type, _Acc, _Cmp>’
/usr/include/kdtree++/kdtree.hpp: In member function ‘void KDTree::KDTree<__K, _Val, _Acc, _Cmp, _Alloc>::_M_optimise(const _Iter&, const _Iter&, size_t)’:
/usr/include/kdtree++/kdtree.hpp:975: error: ‘sort’ is not a member of ‘std’

Revision history for this message
Bart Kroon (bart-kroon) wrote :

Made some changes to get this thing compiling:

diff -r kdtree++/allocator.hpp /usr/include/kdtree++/allocator.hpp
21c21
< typedef ::KDTree::_Node<_Tp> _Node;
---
> typedef _Node<_Tp> _Node;
diff -r kdtree++/kdtree.hpp /usr/include/kdtree++/kdtree.hpp
56d55
< #include <algorithm>
91c90
< typedef ::KDTree::_Node_compare<_Val, _Acc, _Cmp> _Node_compare;
---
> typedef _Node_compare<_Val, _Acc, _Cmp> _Node_compare;
93c92
< typedef ::KDTree::_Region<__K, _Val, typename _Acc::result_type, _Acc, _Cmp>
---
> typedef _Region<__K, _Val, typename _Acc::result_type, _Acc, _Cmp>

The problem is discussed here http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/210c1976-f19a-4064-b415-032390a18dd6/ and the answer is given by Carl Daniel halfway the thread:

inside the defintion of _Alloc_base, we have:

      typedef _Node<_Tp> _Node;

but at namespace scope we have:

     template <typename _Val>
     struct _Node : public _Node_base

Revision history for this message
Yani Ioannou (yani) wrote :

As a follow up to Bart here is the full unified patch for libkdtree++ 6.2 support of GCC 4.3. Having the unpatched libkdtree++ in Intrepid without it doesn't make much sense given GCC 4.3 is now the default compiler!

Revision history for this message
Sebastian Ramacher (s-ramacher) wrote :

Fixed in 0.7.0-2.

affects: libkdtree++ (Ubuntu) → ubuntu
Changed in ubuntu:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.