jlblancoc / nanoflann

nanoflann: a C++11 header-only library for Nearest Neighbor (NN) search with KD-trees

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to compile with apple clang

alecjacobson opened this issue · comments

It seems clang doesn't like variadic args after default values.

In file included from /Users/ajx/Repos/kmeans/build/nanoflann/examples/pointcloud_custom_metric.cpp:32:
/Users/ajx/Repos/kmeans/build/nanoflann/include/nanoflann.hpp:1344:70: error: missing default argument on parameter 'args'
        const KDTreeSingleIndexAdaptorParams& params = {}, Args&&... args)
                                                                     ^
/Users/ajx/Repos/kmeans/build/nanoflann/examples/pointcloud_custom_metric.cpp:102:18: note: in instantiation of function template specialization
      'nanoflann::KDTreeSingleIndexAdaptor<My_Custom_Metric_Adaptor<double, PointCloud<double>, double, unsigned int>, PointCloud<double>, 3,
      unsigned int>::KDTreeSingleIndexAdaptor<const double &>' requested here
    my_kd_tree_t index(3 /*dim*/, cloud, {10 /* max leaf */}, myMetricParam);

I'm using

clang++ --version                                                                                                                          (base) 
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

FWIW v1.3.2 works. Seems like the problem started with 2baa030

Ok, I will try to replicate with a non-apple version of clang to find out the real reason of this. If someone finds it earlier, PRs are welcome! :-)

I tried with clang-15 and it builds ok... weird.
Can you show the full compiler line ? e.g. VERBOSE=1 make

Same error with gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

/XXX/include/nanoflann.hpp:1342:5: error: default argument missing for parameter 4 of ‘nanoflann::KDTreeSingleIndexAdaptor<Distance, DatasetAdaptor, DIM, AccessorType>::KDTreeSingleIndexAdaptor(nanoflann::KDTreeSingleIndexAdaptor<Distance, DatasetAdaptor, DIM, AccessorType>::Dimension, const DatasetAdaptor&, const nanoflann::KDTreeSingleIndexAdaptorParams&, Args&& ...)’
     KDTreeSingleIndexAdaptor(
     ^

cc @jruiu

Problem seems to be with those compiler versions rather than the library, since the code which they are not accepting is valid C++ code according to standard (see https://timsong-cpp.github.io/cppwp/n4140/dcl.fct.default#4): function parameter packs after a parameter with default argument.

Following PR makes the project compile with the defective gcc (<= 4.8.5) and clang (<=10.0.1) versions (and later): #176