http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50732
Bug #: 50732 Summary: [type_traits] is_base_of<Base, Derived> unnecessarily instantiates Base (which shouldn't be instantiated) Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: mimomo...@gmail.com Created attachment 25504 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25504 Test case (which fails to be compiled) Let `Base` be an instance of a class template. By FDIS 20.9.4.3 p3, `Base` can be incomplete type and its instantiation should be avoided in `is_base_of<Base, Derived>`. But, as can be seen below, g++ erroneously instantiates `Base` when its definition is visible. The following code compiles fine: #include <iostream> #include <type_traits> template <typename T> struct non_instantiatable; int main (int argc, char* argv[]) { std::cout << std::is_base_of<non_instantiatable<int>, void>::value << std::endl; return 0; } But if we add the definition, the code fails to compile, since g++ tries to instantiate `non_instantiatable<int>`: #include <iostream> #include <type_traits> template <typename T> struct non_instantiatable { typedef typename T::THIS_TYPE_CANNOT_BE_INSTANTIATED type; }; int main (int argc, char* argv[]) { std::cout << std::is_base_of<non_instantiatable<int>, void>::value << std::endl; return 0; } Tested on g++ 4.7.0 20111008 (experimental).