I have a strange problem with gcc 5.1.0. The following minimum code
// header 1 namespace A { template<typename X> inline constexpr X square(X x) { return x*x; } } // header 2 namespace A { namespace B { template<typename X> struct matrix { XA[3][3]; }; template<typename X> matrix<X> square(matrix<X> const&) noexcept; } } // source, includes both headers namespace A { namespace B { using A::square; // no problem without this line template<typename X> matrix<X> square(matrix<X> const&M) noexcept { matrix<X> R; for(int i=0; i!=3; ++i) for(int j=0; j!=3; ++j) RA[i][j] = MA[i][0]*MA[0][j] + MA[i][1]*MA[1][j] + MA[i][2]*MA[2][j] ; return R; } template matrix<double> square(matrix<double> const&) noexcept; } }
causes a compiler error
test.cc:28:59: error: 'A::B::matrix<double> A::B::square(const A::B::matrix<double>&)' is not declared in 'A::B' template matrix<double> square(matrix<double> const&) noexcept;
The error will disappear if the line specified in the source is deleted. The code compiles with clang ++, but gcc 4.8 also shows an error. I tried unsuccessfully to find the appropriate gcc bugzilla error report, but that can't mean anything. So my main question (s): is this really a gcc bug, and if so, is this new?
This may be due to the ancient error 37374 , which showed similar behavior without a pattern. I registered a new report.
source share