http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54376
Bug #: 54376 Summary: incorrect complaint about redefinition Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: drepper....@gmail.com At least I think this is a compiler problem. I cannot see anything wrong in the libstdc++ code or in my test code. Compiling the following code with 4.7.0 or even the current trunk version of the compiler will produce an error like this. There is no double inclusion problem and still the line with the redefinition is exactly the same as the definition. If you take out one of the two variable definitions and uses the error disappears which indicates the problem is that the compiler doesn't distinguish instantiations correctly. The other pairs of instantiations also produce the same type of mistake. In file included from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/random:50:0, from r3.cc:3: /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/random.h: In instantiation of ‘class std::lognormal_distribution<double>’: r3.cc:31:39: required from here /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/random.h:2279:9: error: redefinition of ‘template<class _RealType1> bool std::operator==(const std::lognormal_distribution<_RealType>&, const std::lognormal_distribution<_RealType>&)’ /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/random.h:2279:9: error: ‘template<class _RealType1> bool std::operator==(const std::lognormal_distribution<_RealType>&, const std::lognormal_distribution<_RealType>&)’ previously defined here Source: #include <functional> #include <iostream> #include <random> template<class E, class D> void measure(const char *name, size_t n, E &e, D &d) { typename D::result_type arr[n]; typename D::result_type s = 0; for (int tries = 0; tries < 100; ++tries) { e.seed(1234); for (size_t i = 0; i < n; ++i) arr[i] = d(e); for (size_t i = 0; i < n; ++i) s += arr[i]; } std::cout << name << " " << n << " = " << " " << s << std::endl; } int main(void) { std::mt19937 e2; std::lognormal_distribution<float> d7; std::lognormal_distribution<double> d8; //std::gamma_distribution<float> d9; //std::gamma_distribution<double> d10; //std::chi_squared_distribution<float> d11; //std::chi_squared_distribution<double> d12; //std::fisher_f_distribution<float> d15; //std::fisher_f_distribution<double> d16; //std::student_t_distribution<float> d17; //std::student_t_distribution<double> d18; //std::binomial_distribution<uint32_t> d20; //std::binomial_distribution<uint64_t> d21; //std::negative_binomial_distribution<uint32_t> d24; //std::negative_binomial_distribution<uint64_t> d25; //std::poisson_distribution<uint32_t> d26; //std::poisson_distribution<uint64_t> d27; for (size_t n = 10; n < 100000; n *= 1.1) { measure("lognormal:32", n, e2, d7); measure("lognormal:64", n, e2, d8); //measure("gamma:32", n, e2, d9); //measure("gamma:64", n, e2, d10); //measure("chi_squared:32", n, e2, d11); //measure("chi_squared:64", n, e2, d12); //measure("fisher_f:32", n, e2, d15); //measure("fisher_f:64", n, e2, d16); //measure("student_t:32", n, e2, d17); //measure("student_t:64", n, e2, d18); //measure("binomial:32", n, e2, d20); //measure("binomial:64", n, e2, d21); //measure("negative_binomial:32", n, e2, d24); //measure("negative_binomial:64", n, e2, d25); //measure("poisson:32", n, e2, d26); //measure("poisson:64", n, e2, d27); } }