Blame


1 c8661ffa 2005-11-29 devnull @node ANSI
2 c8661ffa 2005-11-29 devnull @chapter @sc{gnu} C++ Conformance to @sc{ansi} C++
3 c8661ffa 2005-11-29 devnull
4 c8661ffa 2005-11-29 devnull These changes in the @sc{gnu} C++ compiler were made to comply more
5 c8661ffa 2005-11-29 devnull closely with the @sc{ansi} base document, @cite{The Annotated C++
6 c8661ffa 2005-11-29 devnull Reference Manual} (the @sc{arm}). Further reducing the divergences from
7 c8661ffa 2005-11-29 devnull @sc{ansi} C++ is a continued goal of the @sc{gnu} C++ Renovation
8 c8661ffa 2005-11-29 devnull Project.
9 c8661ffa 2005-11-29 devnull
10 c8661ffa 2005-11-29 devnull @b{Section 3.4}, @i{Start and Termination}. It is now invalid to take
11 c8661ffa 2005-11-29 devnull the address of the function @samp{main()}.
12 c8661ffa 2005-11-29 devnull
13 c8661ffa 2005-11-29 devnull @b{Section 4.8}, @i{Pointers to Members}. The compiler produces
14 c8661ffa 2005-11-29 devnull an error for trying to convert between a pointer to a member and the type
15 c8661ffa 2005-11-29 devnull @samp{void *}.
16 c8661ffa 2005-11-29 devnull
17 c8661ffa 2005-11-29 devnull @b{Section 5.2.5}, @i{Increment and Decrement}. It is an error to use
18 c8661ffa 2005-11-29 devnull the increment and decrement operators on an enumerated type.
19 c8661ffa 2005-11-29 devnull
20 c8661ffa 2005-11-29 devnull @b{Section 5.3.2}, @i{Sizeof}. Doing @code{sizeof} on a function is now
21 c8661ffa 2005-11-29 devnull an error.
22 c8661ffa 2005-11-29 devnull
23 c8661ffa 2005-11-29 devnull @b{Section 5.3.4}, @i{Delete}. The syntax of a @i{cast-expression} is
24 c8661ffa 2005-11-29 devnull now more strictly controlled.
25 c8661ffa 2005-11-29 devnull
26 c8661ffa 2005-11-29 devnull @b{Section 7.1.1}, @i{Storage Class Specifiers}. Using the
27 c8661ffa 2005-11-29 devnull @code{static} and @code{extern} specifiers can now only be applied to
28 c8661ffa 2005-11-29 devnull names of objects, functions, and anonymous unions.
29 c8661ffa 2005-11-29 devnull
30 c8661ffa 2005-11-29 devnull @b{Section 7.1.1}, @i{Storage Class Specifiers}. The compiler no longer complains
31 c8661ffa 2005-11-29 devnull about taking the address of a variable which has been declared to have @code{register}
32 c8661ffa 2005-11-29 devnull storage.
33 c8661ffa 2005-11-29 devnull
34 c8661ffa 2005-11-29 devnull @b{Section 7.1.2}, @i{Function Specifiers}. The compiler produces an
35 c8661ffa 2005-11-29 devnull error when the @code{inline} or @code{virtual} specifiers are
36 c8661ffa 2005-11-29 devnull used on anything other than a function.
37 c8661ffa 2005-11-29 devnull
38 c8661ffa 2005-11-29 devnull @b{Section 8.3}, @i{Function Definitions}. It is now an error to shadow
39 c8661ffa 2005-11-29 devnull a parameter name with a local variable; in the past, the compiler only
40 c8661ffa 2005-11-29 devnull gave a warning in such a situation.
41 c8661ffa 2005-11-29 devnull
42 c8661ffa 2005-11-29 devnull @b{Section 8.4.1}, @i{Aggregates}. The rules concerning declaration of
43 c8661ffa 2005-11-29 devnull an aggregate are now all checked in the @sc{gnu} C++ compiler; they
44 c8661ffa 2005-11-29 devnull include having no private or protected members and no base classes.
45 c8661ffa 2005-11-29 devnull
46 c8661ffa 2005-11-29 devnull @b{Section 8.4.3}, @i{References}. Declaring an array of references is
47 c8661ffa 2005-11-29 devnull now forbidden. Initializing a reference with an initializer list is
48 c8661ffa 2005-11-29 devnull also considered an error.
49 c8661ffa 2005-11-29 devnull
50 c8661ffa 2005-11-29 devnull @b{Section 9.5}, @i{Unions}. Global anonymous unions must be declared
51 c8661ffa 2005-11-29 devnull @code{static}.
52 c8661ffa 2005-11-29 devnull
53 c8661ffa 2005-11-29 devnull @b{Section 11.4}, @i{Friends}. Declaring a member to be a friend of a
54 c8661ffa 2005-11-29 devnull type that has not yet been defined is an error.
55 c8661ffa 2005-11-29 devnull
56 c8661ffa 2005-11-29 devnull @b{Section 12.1}, @i{Constructors}. The compiler generates a
57 c8661ffa 2005-11-29 devnull default copy constructor for a class if no constructor has been declared.
58 c8661ffa 2005-11-29 devnull
59 c8661ffa 2005-11-29 devnull @ignore
60 c8661ffa 2005-11-29 devnull @b{Section 12.4}, @i{Destructors}. In accordance with the @sc{ansi} C++
61 c8661ffa 2005-11-29 devnull draft standard working paper, a pure virtual destructor must now be
62 c8661ffa 2005-11-29 devnull defined.
63 c8661ffa 2005-11-29 devnull @end ignore
64 c8661ffa 2005-11-29 devnull
65 c8661ffa 2005-11-29 devnull @b{Section 12.6.2}, @i{Special Member Functions}. When using a
66 c8661ffa 2005-11-29 devnull @i{mem-initializer} list, the compiler will now initialize class members
67 c8661ffa 2005-11-29 devnull in declaration order, not in the order in which you specify them.
68 c8661ffa 2005-11-29 devnull Also, the compiler enforces the rule that non-static @code{const}
69 c8661ffa 2005-11-29 devnull and reference members must be initialized with a @i{mem-initializer}
70 c8661ffa 2005-11-29 devnull list when their class does not have a constructor.
71 c8661ffa 2005-11-29 devnull
72 c8661ffa 2005-11-29 devnull @b{Section 12.8}, @i{Copying Class Objects}. The compiler generates
73 c8661ffa 2005-11-29 devnull default copy constructors correctly, and supplies default assignment
74 c8661ffa 2005-11-29 devnull operators compatible with user-defined ones.
75 c8661ffa 2005-11-29 devnull
76 c8661ffa 2005-11-29 devnull @b{Section 13.4}, @i{Overloaded Operators}. An overloaded operator may
77 c8661ffa 2005-11-29 devnull no longer have default arguments.
78 c8661ffa 2005-11-29 devnull
79 c8661ffa 2005-11-29 devnull @b{Section 13.4.4}, @i{Function Call}. An overloaded @samp{operator ()}
80 c8661ffa 2005-11-29 devnull must be a non-static member function.
81 c8661ffa 2005-11-29 devnull
82 c8661ffa 2005-11-29 devnull @b{Section 13.4.5}, @i{Subscripting}. An overloaded @samp{operator []}
83 c8661ffa 2005-11-29 devnull must be a non-static member function.
84 c8661ffa 2005-11-29 devnull
85 c8661ffa 2005-11-29 devnull @b{Section 13.4.6}, @i{Class Member Access}. An overloaded @samp{operator ->}
86 c8661ffa 2005-11-29 devnull must be a non-static member function.
87 c8661ffa 2005-11-29 devnull
88 c8661ffa 2005-11-29 devnull @b{Section 13.4.7}, @i{Increment and Decrement}. The compiler will now
89 c8661ffa 2005-11-29 devnull make sure a postfix @samp{@w{operator ++}} or @samp{@w{operator --}} has an
90 c8661ffa 2005-11-29 devnull @code{int} as its second argument.
91 c8661ffa 2005-11-29 devnull
92 c8661ffa 2005-11-29 devnull
93 c8661ffa 2005-11-29 devnull @node Encoding
94 c8661ffa 2005-11-29 devnull @chapter Name Encoding in @sc{gnu} C++
95 c8661ffa 2005-11-29 devnull
96 c8661ffa 2005-11-29 devnull @c FIXME!! rewrite name encoding section
97 c8661ffa 2005-11-29 devnull @c ...to give complete rules rather than diffs from ARM.
98 c8661ffa 2005-11-29 devnull @c To avoid plagiarism, invent some different way of structuring the
99 c8661ffa 2005-11-29 devnull @c description of the rules than what ARM uses.
100 c8661ffa 2005-11-29 devnull
101 c8661ffa 2005-11-29 devnull @cindex mangling
102 c8661ffa 2005-11-29 devnull @cindex name encoding
103 c8661ffa 2005-11-29 devnull @cindex encoding information in names
104 c8661ffa 2005-11-29 devnull In order to support its strong typing rules and the ability to provide
105 c8661ffa 2005-11-29 devnull function overloading, the C++ programming language @dfn{encodes}
106 c8661ffa 2005-11-29 devnull information about functions and objects, so that conflicts across object
107 c8661ffa 2005-11-29 devnull files can be detected during linking. @footnote{This encoding is also
108 c8661ffa 2005-11-29 devnull sometimes called, whimsically enough, @dfn{mangling}; the corresponding
109 c8661ffa 2005-11-29 devnull decoding is sometimes called @dfn{demangling}.} These rules tend to be
110 c8661ffa 2005-11-29 devnull unique to each individual implementation of C++.
111 c8661ffa 2005-11-29 devnull
112 c8661ffa 2005-11-29 devnull The scheme detailed in the commentary for 7.2.1 of @cite{The Annotated
113 c8661ffa 2005-11-29 devnull Reference Manual} offers a description of a possible implementation
114 c8661ffa 2005-11-29 devnull which happens to closely resemble the @code{cfront} compiler. The
115 c8661ffa 2005-11-29 devnull design used in @sc{gnu} C++ differs from this model in a number of ways:
116 c8661ffa 2005-11-29 devnull
117 c8661ffa 2005-11-29 devnull @itemize @bullet
118 c8661ffa 2005-11-29 devnull @item
119 c8661ffa 2005-11-29 devnull In addition to the basic types @code{void}, @code{char}, @code{short},
120 c8661ffa 2005-11-29 devnull @code{int}, @code{long}, @code{float}, @code{double}, and @code{long
121 c8661ffa 2005-11-29 devnull double}, @sc{gnu} C++ supports two additional types: @code{wchar_t}, the wide
122 c8661ffa 2005-11-29 devnull character type, and @code{long long} (if the host supports it). The
123 c8661ffa 2005-11-29 devnull encodings for these are @samp{w} and @samp{x} respectively.
124 c8661ffa 2005-11-29 devnull
125 c8661ffa 2005-11-29 devnull @item
126 c8661ffa 2005-11-29 devnull According to the @sc{arm}, qualified names (e.g., @samp{foo::bar::baz}) are
127 c8661ffa 2005-11-29 devnull encoded with a leading @samp{Q}. Followed by the number of
128 c8661ffa 2005-11-29 devnull qualifications (in this case, three) and the respective names, this
129 c8661ffa 2005-11-29 devnull might be encoded as @samp{Q33foo3bar3baz}. @sc{gnu} C++ adds a leading
130 c8661ffa 2005-11-29 devnull underscore to the list, producing @samp{_Q33foo3bar3baz}.
131 c8661ffa 2005-11-29 devnull
132 c8661ffa 2005-11-29 devnull @item
133 c8661ffa 2005-11-29 devnull The operator @samp{*=} is encoded as @samp{__aml}, not @samp{__amu}, to
134 c8661ffa 2005-11-29 devnull match the normal @samp{*} operator, which is encoded as @samp{__ml}.
135 c8661ffa 2005-11-29 devnull
136 c8661ffa 2005-11-29 devnull @c XXX left out ->(), __wr
137 c8661ffa 2005-11-29 devnull @item
138 c8661ffa 2005-11-29 devnull In addition to the normal operators, @sc{gnu} C++ also offers the minimum and
139 c8661ffa 2005-11-29 devnull maximum operators @samp{>?} and @samp{<?}, encoded as @samp{__mx} and
140 c8661ffa 2005-11-29 devnull @samp{__mn}, and the conditional operator @samp{?:}, encoded as @samp{__cn}.
141 c8661ffa 2005-11-29 devnull
142 c8661ffa 2005-11-29 devnull @cindex destructors, encoding of
143 c8661ffa 2005-11-29 devnull @cindex constructors, encoding of
144 c8661ffa 2005-11-29 devnull @item
145 c8661ffa 2005-11-29 devnull Constructors are encoded as simply @samp{__@var{name}}, where @var{name}
146 c8661ffa 2005-11-29 devnull is the encoded name (e.g., @code{3foo} for the @code{foo} class
147 c8661ffa 2005-11-29 devnull constructor). Destructors are encoded as two leading underscores
148 c8661ffa 2005-11-29 devnull separated by either a period or a dollar sign, depending on the
149 c8661ffa 2005-11-29 devnull capabilities of the local host, followed by the encoded name. For
150 c8661ffa 2005-11-29 devnull example, the destructor @samp{foo::~foo} is encoded as @samp{_$_3foo}.
151 c8661ffa 2005-11-29 devnull
152 c8661ffa 2005-11-29 devnull @item
153 c8661ffa 2005-11-29 devnull Virtual tables are encoded with a prefix of @samp{_vt}, rather than
154 c8661ffa 2005-11-29 devnull @samp{__vtbl}. The names of their classes are separated by dollar signs
155 c8661ffa 2005-11-29 devnull (or periods), and not encoded as normal: the virtual table for
156 c8661ffa 2005-11-29 devnull @code{foo} is @samp{__vt$foo}, and the table for @code{foo::bar} is
157 c8661ffa 2005-11-29 devnull named @samp{__vt$foo$bar}.
158 c8661ffa 2005-11-29 devnull
159 c8661ffa 2005-11-29 devnull @item
160 c8661ffa 2005-11-29 devnull Static members are encoded as a leading underscore, followed by the
161 c8661ffa 2005-11-29 devnull encoded name of the class in which they appear, a separating dollar sign
162 c8661ffa 2005-11-29 devnull or period, and finally the unencoded name of the variable. For example,
163 c8661ffa 2005-11-29 devnull if the class @code{foo} contains a static member @samp{bar}, its
164 c8661ffa 2005-11-29 devnull encoding would be @samp{_3foo$bar}.
165 c8661ffa 2005-11-29 devnull
166 c8661ffa 2005-11-29 devnull @item
167 c8661ffa 2005-11-29 devnull @sc{gnu} C++ is not as aggressive as other compilers when it comes to always
168 c8661ffa 2005-11-29 devnull generating @samp{Fv} for functions with no arguments. In particular,
169 c8661ffa 2005-11-29 devnull the compiler does not add the sequence to conversion operators. The
170 c8661ffa 2005-11-29 devnull function @samp{foo::bar()} is encoded as @samp{bar__3foo}, not
171 c8661ffa 2005-11-29 devnull @samp{bar__3fooFv}.
172 c8661ffa 2005-11-29 devnull
173 c8661ffa 2005-11-29 devnull @item
174 c8661ffa 2005-11-29 devnull The argument list for methods is not prefixed by a leading @samp{F}; it
175 c8661ffa 2005-11-29 devnull is considered implied.
176 c8661ffa 2005-11-29 devnull
177 c8661ffa 2005-11-29 devnull @item
178 c8661ffa 2005-11-29 devnull @sc{gnu} C++ approaches the task of saving space in encodings
179 c8661ffa 2005-11-29 devnull differently from that noted in the @sc{arm}. It does use the
180 c8661ffa 2005-11-29 devnull @samp{T@var{n}} and @samp{N@var{x}@var{y}} codes to signify copying the
181 c8661ffa 2005-11-29 devnull @var{n}th argument's type, and making the next @var{x} arguments be the
182 c8661ffa 2005-11-29 devnull type of the @var{y}th argument, respectively. However, the values for
183 c8661ffa 2005-11-29 devnull @var{n} and @var{y} begin at zero with @sc{gnu} C++, whereas the
184 c8661ffa 2005-11-29 devnull @sc{arm} describes them as starting at one. For the function @samp{foo
185 c8661ffa 2005-11-29 devnull (bartype, bartype)}, @sc{gnu} C++ uses @samp{foo__7bartypeT0}, while
186 c8661ffa 2005-11-29 devnull compilers following the @sc{arm} example generate @samp{foo__7bartypeT1}.
187 c8661ffa 2005-11-29 devnull
188 c8661ffa 2005-11-29 devnull @c Note it loses on `foo (int, int, int, int, int)'.
189 c8661ffa 2005-11-29 devnull @item
190 c8661ffa 2005-11-29 devnull @sc{gnu} C++ does not bother using the space-saving methods for types whose
191 c8661ffa 2005-11-29 devnull encoding is a single character (like an integer, encoded as @samp{i}).
192 c8661ffa 2005-11-29 devnull This is useful in the most common cases (two @code{int}s would result in
193 c8661ffa 2005-11-29 devnull using three letters, instead of just @samp{ii}).
194 c8661ffa 2005-11-29 devnull @end itemize
195 c8661ffa 2005-11-29 devnull
196 c8661ffa 2005-11-29 devnull @c @node Cfront
197 c8661ffa 2005-11-29 devnull @c @chapter @code{cfront} Compared to @sc{gnu} C++
198 c8661ffa 2005-11-29 devnull @c
199 c8661ffa 2005-11-29 devnull @c
200 c8661ffa 2005-11-29 devnull @c FIXME!! Fill in. Consider points in the following:
201 c8661ffa 2005-11-29 devnull @c
202 c8661ffa 2005-11-29 devnull @c @display
203 c8661ffa 2005-11-29 devnull @c Date: Thu, 2 Jan 92 21:35:20 EST
204 c8661ffa 2005-11-29 devnull @c From: raeburn@@cygnus.com
205 c8661ffa 2005-11-29 devnull @c Message-Id: <9201030235.AA10999@@cambridge.cygnus.com>
206 c8661ffa 2005-11-29 devnull @c To: mrs@@charlie.secs.csun.edu
207 c8661ffa 2005-11-29 devnull @c Cc: g++@@cygnus.com
208 c8661ffa 2005-11-29 devnull @c Subject: Re: ARM and GNU C++ incompatabilities
209 c8661ffa 2005-11-29 devnull @c
210 c8661ffa 2005-11-29 devnull @c Along with that, we should probably describe how g++ differs from
211 c8661ffa 2005-11-29 devnull @c cfront, in ways that the users will notice. (E.g., cfront supposedly
212 c8661ffa 2005-11-29 devnull @c allows "free (new char[10])"; does g++? How do the template
213 c8661ffa 2005-11-29 devnull @c implementations differ? "New" placement syntax?)
214 c8661ffa 2005-11-29 devnull @c @end display
215 c8661ffa 2005-11-29 devnull @c
216 c8661ffa 2005-11-29 devnull @c XXX For next revision.
217 c8661ffa 2005-11-29 devnull @c
218 c8661ffa 2005-11-29 devnull @c GNU C++:
219 c8661ffa 2005-11-29 devnull @c * supports expanding inline functions in many situations,
220 c8661ffa 2005-11-29 devnull @c including those which have static objects, use `for' statements,
221 c8661ffa 2005-11-29 devnull @c and other situations. Part of this versatility is due to is
222 c8661ffa 2005-11-29 devnull @c ability to not always generate temporaries for assignments.
223 c8661ffa 2005-11-29 devnull @c * deliberately allows divide by 0 and mod 0, since [according
224 c8661ffa 2005-11-29 devnull @c to Wilson] there are actually situations where you'd like to allow
225 c8661ffa 2005-11-29 devnull @c such things. Note on most systems it will cause some sort of trap
226 c8661ffa 2005-11-29 devnull @c or bus error. Cfront considers it an error.
227 c8661ffa 2005-11-29 devnull @c * does [appear to] support nested classes within templates.
228 c8661ffa 2005-11-29 devnull @c * conversion functions among baseclasses are all usable by
229 c8661ffa 2005-11-29 devnull @c a class that's derived from all of those bases.
230 c8661ffa 2005-11-29 devnull @c * sizeof works even when the class is defined within its ()'s
231 c8661ffa 2005-11-29 devnull @c * conditional expressions work with member fns and pointers to
232 c8661ffa 2005-11-29 devnull @c members.
233 c8661ffa 2005-11-29 devnull @c * can handle non-trivial declarations of variables within switch
234 c8661ffa 2005-11-29 devnull @c statements.
235 c8661ffa 2005-11-29 devnull @c
236 c8661ffa 2005-11-29 devnull @c Cfront: