Opened 13 years ago

Closed 13 years ago

#3492 closed Bugs (invalid)

Code using Boost accumulators fails to compile in ubuntu amd64 gcc 4.4.1

Reported by: ramon.casellas@… Owned by: Eric Niebler
Milestone: Boost 1.41.0 Component: accumulator
Version: Boost 1.40.0 Severity: Regression
Keywords: accumulator template tag error_of moment Cc:

Description

Hello,

The following code (simplified)

#include <iostream>
#include <iomanip>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/foreach.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/min.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/accumulators/statistics/error_of.hpp>
#include <boost/accumulators/statistics/error_of_mean.hpp>
#include <boost/accumulators/statistics/moment.hpp>
#include <boost/accumulators/statistics/density.hpp>
using namespace boost::accumulators;

int main(int argc, char* argv[])
{
        std::vector< double > data;
        std::copy(std::istream_iterator<double>(std::cin), std::istream_iterator<double>(), std::back_inserter(data));
        data.erase(std::remove_if (data.begin(), data.end(), negative), data.end());

        // changed features->stats, same result
        accumulator_set<double, stats<tag::count, tag::density, tag::min, tag::max, tag::mean, tag::error_of<tag::mean>, tag::variance, tag::moment<2> > > acc
                (
                 tag::density::cache_size = data.size(),
                 tag::density::num_bins = 16
                );
        std::for_each(data.begin(), data.end(), boost::bind<void>( boost::ref(acc), _1 ) );

        // Display the results ...
        if (argc == 1)
        {
                std::cout << "Samples:   "   << count(acc) << std::endl;
                std::cout << "Mean:      "   << mean(acc) << std::endl;
                std::cout << "ErrorOf:   "   << error_of< tag::mean >(acc)<< std::endl;
                std::cout << "Moment 2:  "   << moment<2>(acc) << std::endl;
                std::cout << "Variance:  "   << extract_result< tag::variance >( acc )<< std::endl;
                std::cout << "Min: "         << extract_result< tag::min >( acc )<< std::endl;
                std::cout << "Max: "         << extract_result< tag::max >( acc )<< std::endl;
        }

fails to compile in Ubuntu 9.10 amd64 gcc 4.4.1

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu4)

/usr/local/include/boost/accumulators/statistics_fwd.hpp: In function ‘int main(int, char**)’:
/usr/local/include/boost/accumulators/statistics_fwd.hpp:72: error: ‘template<class Feature> struct boost::accumulators::tag::error_of’ is not a function,
/usr/local/include/boost/accumulators/statistics/error_of.hpp:77: error:   conflict with ‘template<class T2, class Arg1, class A0, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14> typename boost::accumulators::detail::extractor_result<Arg1, boost::accumulators::tag::error_of<T2> >::type boost::accumulators::extract::error_of(const Arg1&, const A0&, const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&, const A12&, const A13&, const A14&)’
main.cpp:100: error:   in call to ‘error_of’
/usr/local/include/boost/accumulators/statistics_fwd.hpp:91: error: ‘template<int N> struct boost::accumulators::tag::moment’ is not a function,
/usr/local/include/boost/accumulators/statistics/moment.hpp:104: error:   conflict with ‘template<int T2, class Arg1, class A0, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14> typename boost::accumulators::detail::extractor_result<Arg1, boost::accumulators::tag::moment<T2> >::type boost::accumulators::extract::moment(const Arg1&, const A0&, const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&, const A12&, const A13&, const A14&)’
main.cpp:101: error:   in call to ‘moment’

The very same code compiles in Debian 5.0 Lenny

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1)

Thanks in advance

Change History (1)

comment:1 by Eric Niebler, 13 years ago

Resolution: invalid
Status: newclosed

Recent versions of gcc take a very "interesting" and unfortunate interpretation of C++'s name lookup rules, and you're getting bitten by them. Since the invocations of 'error_of' and 'moment' have (some of) their template parameters explicitly specified, name look-up is finding the *types* 'error_of' and 'moment' in addition to the functions, and the ambiguity is causing an error. This is a problem with gcc's peculiar interpretation of name look-up, not a problem in accumulators.

You can work around the problem by adding namespace qualification to the invocations of 'error_of' and 'moment':

  namespace acc = boost::accumulators;
  acc::moment<2>(acc);
Note: See TracTickets for help on using tickets.