RAD Studio
ContentsIndex
PreviousUpNext
Stricter C++ Compiler (C++Builder 2007)

To more closely obey the rules of the C++ ANSI Standard, the C++ compiler shipping with C++Builder 2007 is stricter than previous versions. Code that did not generate errors in earlier versions of C++Builder might fail to compile beginning with C++Builder 2007.  

This section lists some of the common areas where the compiler is stricter. Each case is illustrated with an example showing the problem and how to update the code to compile with C++Builder 2007. Note that there are often many ways to bring offending code up to date. The appropriate method depends on the intent of the original code.

Name 
Description 
There are many constructs that now generate error messages from the CodeGear C++ compiler included with C++Builder 2007 and newer releases. The rules governing this behavior are described in section 8.5.3 of the 2003 C++ ANSI standard.
The rules can be divided into the following categories (with the compiler switch that overrides this behavior):
  • Binding a non-const lvalue to to non-const reference. (Use the compiler switch -Vbr to allow this.)
  • Binding a temporary to a non-const reference. (Use the compiler switch -Vbr to allow this.)
  • Binding of const or volatile objects to non-const or non-volatile methods repectively. (Use the compiler... more 
String literals are now considered to be of type 'const char[]' by default. This, combined with the stricter qualification binding of const values and types, can generate error messages in code that compiled before.
You might enable the -Vbs switch to revert string literals to non-const. However, CodeGear recommends that you update the code instead.
Note that the change in the type of string literals can also change how the compiler resolves calls to overloaded methods. The following example illustrates this:  
The C++ compiler no longer allows an explicit template without the 'template <>' prefix. Use the compiler switch -Vbe to allow this. The following example shows this:  
One of the areas where the C++Builder 2007 compiler differs the most from the previous versions is in overload resolution, which includes the detection of ambiguity. The compiler now better conforms to the rules in section 13.3 of the 2003 C++ ANSI Standard. Several constructs that were previously allowed might now be reported as ambiguous or no match found, requiring that you modify code to clarify its intent.
The compiler option -Vbo reverts to the old behavior, not enforcing the new stricter behavior. However, not all compiler changes can be controlled by this switch, so CodeGear recommends that you update... more 
The compiler now obeys the rules of 8.5.1 and 13.3.1 of the 2003 C++ ANSI Standard for initialization and conversion:
  • Direct initialization now requires initialization by a constructor and no longer picks a user conversion sequence.
  • Copy initialization for objects of the same or derived type now requires a constructor call.
  • Copy initialization for objects of the different types no longer prefers user conversion over construction. If the compiler finds a suitable user conversion, it now continues to look for (possibly ambiguous) converting constructors. If the chosen conversion function is a converting constructor, the call initializes a temporary of the... more 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!