Code: --------------- template <bool x> struct tester; template <> struct tester<true> { enum { value = 1 }; };
template <class T> struct allow_double_instantiations { static const bool value = false; }; template <int Power> class FixedPoint { static const bool allow_double_instantiations = false; typedef FixedPoint<Power> Self; public: FixedPoint(): mValue(0) {} //Default copy c'tor, assignment op valid & useful. Self &operator=(double const &d) { mValue = sizeof(tester<Self::allow_double_instantiations>); return *this; } int mValue; }; void foo(FixedPoint<4> &); int main() { FixedPoint<4> x; foo(x); return 0; } template <> FixedPoint<4> &FixedPoint<4>::operator=(double const &d) { mValue = int(d); return *this; } void foo(FixedPoint<4> &t) { t = 13.5; } ------------- gcc 4.3.2 and earlier versions compile this without complaint; 4.4.3 dies with test_fixedpoint.C: In member function `FixedPoint<Power>& FixedPoint<Power>::operator=(const double&)': test_fixedpoint.C:21: error: invalid application of `sizeof' to incomplete type `tester<false>' By my reading of the standard, the invalid definition of operator= should not be attempted to be instantiated until line 43, where the valid template specialization has been seen, and previous versions of g++ agree with me. Note that in the original code, line 21 was a BOOST_STATIC_ASSERT and produced the same result. -- Summary: 4.4 regression: Attempts to instantiate unnecessary code Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: georgeh at rentec dot com GCC target triplet: i686-suse-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43522