Publications:A Semantic Analysis of C++ Templates

Jump to: navigation, search

Do not edit this section

Keep all hand-made modifications below

Title A Semantic Analysis of C++ Templates
Author Jeremy Siek and Walid Taha
Year 2006
PublicationType Conference Paper
HostPublication ECOOP 2006 - Object-Oriented Programming : 20th European Conference, Nantes, France, July 3-7, 2006, Proceedings
Conference 20th European Conference on Object-Oriented Programming (ECOOP 2006), Nantes, FRANCE, APR 03-JUL 07, 2006
Diva url
Abstract Templates are a powerful but poorly understood feature ofthe C++ language. Their syntax resembles the parameterized classes ofother languages (e.g., of Java). But because C++ supports template specialization, their semantics is quite different from that of parameterizedclasses. Template specialization provides a Turing-complete sub-languagewithin C++ that executes at compile-time. Programmers put this powerto many uses. For example, templates are a popular tool for writingprogram generators.The C++ Standard defines the semantics of templates using natural language, so it is prone to misinterpretation. The meta-theoretic propertiesof C++ templates have not been studied, so the semantics of templateshas not been systematically checked for errors. In this paper we presentthe first formal account of C++ templates including some of the morecomplex aspects, such as template partial specialization. We validate oursemantics by proving type safety and verify the proof with the Isabelleproof assistant. Our formalization reveals two interesting issues in theC++ Standard: the first is a problem with member instantiation and thesecond concerns the generation of unnecessary template specializations.