Draft:C++03
| C++ language revisions |
|---|
C++03 was a revision of the C++ programming language standard that focused on fixing bugs and clarifying the original C++98 standard. It was originally published as ISO/IEC 14882:2003 by the International Organization for Standardization (ISO) and the International Electrotechnical Commision (IEC). It was primarily a bug fix release for implementers, in order to ensure greater consistency and portability.[1] C++03 replaced the prior C++98 standard, and was eventually replaced by C++11. The revision addressed 92 core language defect reports[2] and 125 library defect reports[3].
Historical Context
[edit]After C++98 was released, many users quickly ran into issues, such as ambiguity, inconsistency, and unspecified behavior. Certain language features lacked clear definitions, and edge cases in many areas led to non-portable code. To resolve these problems without sacrificing backwards compatibility, the ISO C++ committee (WG21) collected Defect Reports (DRs) and worked on refining the standard. This process was continued until 2003, when C++03 was released.
Value Initialization
[edit]Value initialization was one of the few new language features added in C++03. It defines how objects are initialized when using an empty initializer (such as T()). For scalar types, it sets the object to zero. For class types, a user-provided constructor is used if it exists, otherwise the non-static data members and base class subobjects are individually value initialized.[4]
This change addressed inconsistent implementation behavior, and clarified common problems, such as expressions like T() zeroing out members or leaving them uninitialized. However, many problems remained. Even with value initialization, non-intuitive behavior can occur, especially when a class has a user-defined constructor that doesn’t explicitly zero its members, or when aggregate initialization is involved. These edge cases were clarified in future versions of the C++ standards.
Library Improvements
[edit]A notable clarification introduced in C++03 involved the behavior of std::vector<T>. With the resolution of Defect Report 69[5], elements in a vector were required to be stored contiguously.[6] This codified the common expectation that a C++ std::vector object had a memory layout similar to an array, which was not guaranteed in C++98.
Template Behavior and Name Lookup
[edit]In addition, the standard formalized how names inside templates are looked up. The standard formalized that non-dependent names (names which don’t depend on template parameters) are looked up at the point of template definition. In contrast, names depending on template parameters are looked up at instantiation.
Other Language Clarification
[edit]Exception specifications (e.g. throw()) were clarified in their semantics: what it means to violate them at runtime, how they interact with exception propagation, and what standard library functions require. While C++03 did not remove legacy throw-specs, it made behavior more precise.
Some initialization rule clarifications include: default vs value vs zero initialization, behavior of new T versus new T(), initialization of built-in types vs. user-defined types, behavior of uninitialized memory in certain class member placements.
The standard also clarified when constructors, copy constructors, and assignment operators are defined implicitly, what makes a type “trivial” or “POD”, and what guarantees are made about these types (e.g. when zeroing, copying, or defaulting apply).
See Also
[edit]- C++ Technical Report 1 - Additions to the C++03 Standard Library
- C++ standard library
References
[edit]- ^ "Stroustrup: FAQ". www.stroustrup.com. Archived from the original on 2016-02-06. Retrieved 2025-09-18.
- ^ "C++ Standard Core Language Issue Index by Status". open-std.org. Retrieved 2025-09-18.
- ^ "LWG Index by Status and Section". open-std.org. Retrieved 2025-09-18.
- ^ "Value-initialization - cppreference.com". en.cppreference.com. Retrieved 2025-09-18.
- ^ "C++ Standard Library Defect Reports and Accepted Issues". open-std.org. Retrieved 2025-09-18.
- ^ Herb, Sutter (2002). More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions. Boston: Pearson Education, Inc. p. 48. ISBN 0-201-70434-X. Archived from the original on 2022-09-21. Retrieved 2022-09-20.
- British Standards Institute (2003-10-01). The C++ Standard: Incorporating Technical Corrigendum No. 1. John Wiley & Sons, Inc. ISBN 978-0-470-84674-2.