Clang-enhanced C++ Compilers

From RAD Studio
Jump to: navigation, search

Go Up to C++ Compilers


The latest generation of RAD Studio C++ compilers is based on the open-source Clang compiler, which is a front end for the LLVM compiler back end.

RAD Studio provides the following Clang-enhanced C++ compilers:

Compiler Platform Clang Version LLVM Version
BCC32C 32-bit Windows 3.3 3.3
BCC64 64-bit Windows 3.3 3.3
BCCIOSARM 32-bit iOS 3.3 3.3
BCCIOSARM64 64-bit iOS 3.3 3.5
BCCAARM Android 3.3 3.3

Differences Between Clang-enhanced C++ Compilers and Previous-Generation C++ Compilers

Clang-enhanced C++ compilers have an entirely new code base, and they differ significantly from the RAD Studio previous-generation C++ compilers:

Here are some of the notable differences between Clang-enhanced C++ compilers and the two previous-generation C++ compilers:

  • Clang-enhanced C++ compilers are also preprocessors when run with the -E switch.
    For 64-bit Windows, there is also a separate CPP64.EXE preprocessor.
  • Clang-enhanced C++ compilers enforce template two-phase lookup.
    That is, names that are not tied to a dependent type are looked-up in the first phase (before instantiation) and might lead to errors that previous-generation C++ compilers did not report. In the second phase (instantiation), the template code is looked up again to ensure all calls are valid for dependent types. For further information, see Two-phase name lookup for Clang.

Eg: The template might perform calls to functions that might not be present for that particular type.

  • Clang-enhanced C++ compilers allow a default argument only in a function declaration.
    Previous-generation C++ compilers allow default arguments in a function pointer or closure declaration as well.
  • Clang-enhanced C++ compilers do not allow the use of sizeof in a preprocessor directive, such as #if sizeof(ATypeName) > 20.
  • Clang-enhanced C++ compilers are stricter about conversions.
    For example, converting string constants to char * generates a warning (conversion from string literal to char * is deprecated). On the other hand, initializing a char * with an unsigned char * results in a plain error (Cannot initialize a variable of type 'char *' with an rvalue of type BYTE *, also known as unsigned char *).
  • Clang-enhanced C++ compilers do not allow you to mix __try with catch: this is because catch must be used with try; and __try must be used with __except and/or __finally.
  • Unicode identifiers are not supported by Clang-enhanced C++ compilers.
  • CPP32 supports the -Hp option and prints header guard information that is used by the Precompiled Header Wizard.
  • The Unix-style #line is not the default #line of CPP32, and so forth.
  • Clang-enhanced C++ compilers do not support the final, deprecated and noreturn C++11 attributes. See Workaround for C++11 attributes for a workaround in Clang-enhanced C++ compilers.
  • Many options of previous-generation C++ compilers are not supported by Clang-enhanced C++ compilers, and vice versa:

For more information, see Differences Between Clang-enhanced C++ Compilers and Previous-Generation C++ Compilers.

How Previous-Generation C++ Compiler Options Translate to Options of Clang-enhanced C++ Compilers

See Project Options Supported by Clang-enhanced C++ Compilers.

Common Issues When Compiling a Previous-Generation C++ Compiler Project Using Clang-enhanced C++ Compilers

You are likely to encounter new errors due to the ANSI-compliant strictness of Clang-enhanced C++ compilers.

For more information, see:

Support for Precompiled Headers

Clang-enhanced C++ compilers support the use of one precompiled header, named by default <project><n>PCH.h.

For further information, see Using Precompiled Headers with Clang-enhanced C++ Compilers.

Predefined Macros

The predefined macros supported by the Clang-enhanced compilers are numerous. For example, BCCIOSARM supports defines such as __APPLE__ and __BCCPLUSPLUS__.

To display all the predefined macros that are supported, use the command-line interface of your compiler as follows:

echo | <compiler> -E -dM -

The -E option runs the preprocessor only. -dM dumps all macros defined during preprocessing and stops. The final - takes input from stdin, which is sent through the pipe from the empty echo.

For more information, see Predefined Macros.

Keywords

This section contains an alphabetical list of C++ keywords that require special considerations when used with Clang-enhanced C++ compilers or are not supported by these compilers.

Supported Not supported

See Workaround for C++11 Attributes (Clang-enhanced C++ Compilers) to learn how to replace the functionality of keywords that are not supported in Clang-enhanced C++ compilers.

Automatic Reference Counting May Be Enabled by Default

The LLVM-based Delphi compilers use automatic reference counting (ARC). If the Delphi compiler for a certain target platform is based on LLVM, the matching Clang-enhanced C++ compiler automatically enables ARC. Enabling ARC is equivalent to passing the -fborland-auto-refcount switch to the command-line interface of the C++ compiler.

The following table shows which Clang-enhanced C++ compilers have ARC enabled by default:

Platform Delphi Compiler C++ Compiler ARC Enabled by Default

32-bit Windows

DCC32

BCC32C

No

64-bit Windows

DCC64

BCC64

No

32-bit iOS

DCCIOSARM

BCCIOSARM

Yes

64-bit iOS

DCCIOSARM64

BCCIOSARM64

Yes

Android

DCCAARM

BCCAARM

Yes

Note: Do not disable ARC on the command line. It is required for working with the FireMonkey and RTL frameworks.

Using Parallel Compilation

Parallel compilation allows compilers to process several source files simultaneously, using separate cores of the system processor, to significantly decrease compilation time.

To enable parallel compilation in the IDE for a certain C++ project, open the target project and follow these steps:

  1. Select Project > Options > C++ Compiler, and enable the "Enable batch compilation" option under General Compilation.
  2. Select Project > Options > Project Properties and:
    1. Enable the "Run C++ compiler in a separate process" option.
    2. Select the number of parallel subprocesses that you want to use.
      Note: The number of subprocesses that you choose cannot be higher than the number of cores of your CPU.

Topics

See Also