Clang-based C++ Compilers

From RAD Studio
Jump to: navigation, search

Go Up to Command-Line Utilities Index

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

RAD Studio provides the following Clang-based compilers:

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

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

Here are some of the notable differences between Clang-based C++ compilers and the two C++ desktop compilers BCC32 and BCCOSX:

  • Clang-based C++ compilers are also preprocessors, when run with the -E switch.
    For 64-bit Windows, there is also a separate CPP64.EXE preprocessor.
  • Clang-based 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 BCC32 did not report.
  • Clang-based C++ compilers allow a default argument only in a function declaration.
    BCC32 allows default arguments in a function pointer or closure declaration as well.
  • Clang-based C++ compilers do not allow the use of sizeof in a preprocessor directive, such as #if sizeof(ATypeName) > 20.
  • Clang-based 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-based 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-based C++ compilers.
  • CPP32 supports the -Hp option and prints header guard information that is used by the Precompiled Header Wizard.
  • CPP32's default is not Unix style #line, and so forth.
  • The final (C++), deprecated and noreturn C++0x attributes are not supported by the Clang-based C++ compilers. See Workaround for C++0x attributes for a workaround in Clang-based C++ compilers.
  • Many BCC32 options are not supported by Clang-based C++ compilers, and vice versa:

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

How BCC32 Options Translate to Options of Clang-based C++ Compilers

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

Common Issues When Compiling a BCC32 Project Using Clang-based C++ Compilers

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

For more information, see:

Options of Clang-based C++ Compilers

Note: Using Clang-based C++ compilers on the command line can have unexpected results. However, the options of Clang-based C++ compilers that are available in the IDE have been tested during implementation. For more information, see:

Clang-based compilers are very similar to one another, and they share most of their command-line options. A subset of the features of Clang have been integrated into RAD Studio, and some of these are available on the C++ Compiler Project Options pages.

Executing at the Command Line

For anyone who calls Clang-based C++ compilers at the command line, we recommend going through the driver, as follows:

<compiler> -c test.cpp


<compiler> -tWCV myApplication.cpp

In this case, Clang-based C++ compilers run with the following command-line parameters enabled by default:

If you are an experienced user of Clang and you want to use the Clang-based C++ compilers without going through the driver, you should pass -cc1 as the first option, telling the compiler that you are taking matters in your hands and want to have total/strict control on all options. In this case, no option is automatically injected for you, and you would need to specify the command-line parameters above manually.

Error Reporting Options

ld: --warn-common     Warn about duplicate common symbols
ld: --warn-unresolved-symbols     Report unresolved symbols as warnings
ld: --error-unresolved-symbols     Report unresolved symbols as errors

Support for Precompiled Headers

Clang-based 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-based C++ Compilers.

To illustrate one basic difference between BCC32 and Clang-based C++ compilers, here are two MAKE-like snippets, one from BCC32 and one from the Clang-based 64-bit Windows C++ compiler, BCC64:

# BCC32 Build
source1.obj: source1.cpp source1.h
  BCC32 -c -H projectPCH.pch source1.cpp
source2.obj: source2.cpp source2.h
  BCC32 -c -H projectPCH.pch source2.cpp
# BCC64 Build
projectPCH.pch: projectPCH.h
  BCC64 -emit-pch -o projectPCH.pch projectPCH.h
source1.obj: projectPCH.pch source1.cpp source1.h
  BCC64 -emit-obj -include-pch projectPCH.pch source1.cpp
source2.obj: projectPCH.pch source2.cpp source2.h
  BCC64 -emit-obj -include-pch projectPCH.pch source2.cpp

The key idea is that there is a specific target for building the project's precompiled header.

Predefined Macros

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

To display all the predefined macros that are supported, enter:

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.

#include Paths and Lookup

Clang-based C++ compilers support three different header/source paths:

  • -isystem is for system headers included with the compiler. Warnings for headers found on this path are suppressed.
  • -I is for headers provided by third parties.
  • -idirafter is for paths searched after paths specified via -I or -isystem have been searched. If the path has a leading '=' character, this character is replaced with the value specified via -sysroot.
  • -iquote is for your own source files and headers. As the name suggests, this path is used only for directives with quotes: #include "file". If the named file is not found, then the paths specified by -I and -isystem are searched, as if the directive was #include <file>.

For more information, see #include.


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

Supported Not supported

See Workaround for C++0x Attributes to learn how to replace the functionality of keywords that are not supported in Clang-based C++ compilers.


See Also