# Clang 3.0 Release Notes

- Introduction
- What's New in Clang 3.0?
  - Major New Features
  - C Language Changes
  - C++ Language Changes
  - Objective-C Language Changes
  - Internal API Changes
- Known Problems
- Additional Information

Written by the LLVM Team

## Introduction

This document contains the release notes for the Clang C/C++/Objective-C frontend, part of the LLVM Compiler Infrastructure, release 3.0. Here we describe the status of Clang in some detail, including major improvements from the previous release and new feature work. For the general LLVM release notes, see the LLVM documentation. All LLVM releases may be downloaded from the LLVM releases web site.

For more information about Clang or LLVM, including information about the latest release, please check out the main please see the Clang Web Site or the LLVM Web Site.

Note that if you are reading this file from a Subversion checkout or the main Clang web page, this document applies to the next release, not the current one. To see the release notes for a specific release, please see the releases page.

## What's New in Clang 3.0?

Some of the major new features and improvements to Clang are listed here. Generic improvements to Clang as a whole or two its underlying infrastructure are described first, followed by language-specific sections with improvements to Clang's support for those languages.

### Major New Features

#### A multitude of improvements to Clang's diagnostics

Clang's diagnostics are constantly being improved to catch more issues, explain them more clearly, and provide more accurate source information about them. A few improvements since the 2.9 release that have a particularly high impact:

- Substantially shorter messages due to better recovery, fewer include stacks, and tuning verbose features such as 'a.k.a.' type printing.
- Able to recover and correct from misspelled type names at the beging of statements. For example, Clang now emits:

      t.c:6:3: error: use of undeclared identifier 'integer'; did you mean 'Integer'?
        integer *i = 0;
        ^~~~~~~
        Integer
      t.c:1:13: note: 'Integer' declared here
      typedef int Integer;
                  ^

- Expanded typo correction to (among other improvements) look across namespaces and suggest namespace qualifiers in addition to misspellings of the identifier itself.
- More rich macro expansion backtraces and some (limited) fix-it hints when diagnostics stem from macro arguments.
- Many new warnings have been added to catch common, bug-prone code patterns.
- Uninitialized values Clang warning was rewritten to be more accurate, faster, and able to differentiate between the possibility of an uninitialized use and the certainty of an uninitialized use.

#### This release saw significant improvements to `libclang`

- A broader set of the `libclang` API is exposed in the Python bindings.
- Much more of the Clang AST is exposed through `libclang`'s APIs and cursors.
- Cursors can now walk more effectively through macros, especially arguments to function-style macros, and resolve to the underlying AST.
- Improved code completion surrounding macros, macro arguments, and token pasting.
- Improved code completion for in-class member functions.
- Crash recovery for `libclang` clients.

#### The Clang GCC-compatible command-line driver improved dramatically

A great deal of work went into the GCC-compatible driver for the 3.0 release making it support more operating systems, emulate GCC behavior more accurately, and support a much broader range of Linux distributions out of the box.

- More accurate support for hardware architecture pre-defined macros (e.g., __i686__).
- Robust library and header search paths for the vast majority of x86 and x86-64 Linux distributions.
- Improved support for newer Darwin platforms.
- Partial support for `--sysroot=...` based cross-compiling on Linux (and similar) host systems.
- Improved support for locating and using libcxx when installed, especially on Darwin.
- Automatic detection of Clang crashes in the driver and preparation of reproduction steps for filing bug reports.

#### Expanded support for instrumenting the preprocessor through callbacks

Several enhancements were made to the `PPCallbacks` interface to expand the information available to tools and library users of Clang that wish to introspect the preprocessing.

- The exact text used between the `""`s or `<>`s is reported.
- The header search path used to locate the header is reported.
- Missing files during including headers reported.
- The exact source range for expanded macros can be retrieved.

#### Clang is building and tested regularly on Windows and can compile limited subsets of code on Windows

Clang is regularly built and tested on a variety of Windows platforms including MinGW 32-bit and 64-bit, Cygwin, and natively with MSVC. In addition, Clang can be used as a compiler in a few Windows contexts.

- Normal compilation supported for the MinGW target platform, in both 32-bit and 64-bit, and the Cygwin target platform.
- Parsing and AST support for Windows Structured Exception Handling.
- New -fms-compatibility flag to handle MSVC constructs that could change the meaning of an otherwise well formed program
- clang can now parse all the MSVC 2010 standard C++ header files in the nominal case, (still need to specifiy -nobuiltininc for some headers).
- Improved support for MFC code parsing, (still a work in progress).
- Add support for function template specialization at class scope (-fms-extensions mode).
- Add support for Microsoft __if_exists/__if_not_exists statements (-fms-extensions mode).

#### New availability attribute to detect and warn about API usage across OS X and iOS versions

Clang now supports an attribute which documents the availability of an API across various platforms and releases, allowing interfaces to include information about what OS versions support the relevant features. Based on the targeted version of a compile, warnings for deprecated and unavailable interfaces will automatically be provided by Clang.

#### Thread Safety annotations and analysis-based warnings

A set of annotations were introduced to Clang to describe the various thread-safety concerns of a program, and an accompanying set of analysis based warnings will diagnose clearly unsafe code patterns. The annotations are described in the extension specification, and the warnings currently supported include:

- Calling functions without the required locks
- Reading variables without the required locks
- Writing to variables without an exclusive lock (even if holding a shared lock)
- Imbalance between locks and unlocks across loop entries and exits
- Acquiring or releasing locks out of order

#### Improved support for partially constructed and/or incomplete ASTs

For users such as LLDB that are dynamically forming C++ ASTs, sometimes it is either necessary or useful to form a partial or incomplete AST. Support for these use cases have improved through the introduction of "unknown" types and other AST constructs designed specifically for use cases without complete information about the C++ construct being formed.

#### Initial work to support compiling OpenCL C with Clang

Clang has some (limited) support for compiling OpenCL C. The 3.0 release adds support for the `vec_step` operator, address space qualifiers (`__private`, `__global`, `__local` and `__constant`), improved vector literal support and code generation support for the PTX target.

Using the libclc library to supply OpenCL C built-ins, you can use Clang to compile OpenCL C code into PTX and execute it by loading the resulting PTX as a binary blob using the nVidia OpenCL library. It has been tested with several OpenCL programs, including some from the nVidia GPU Computing SDK, and the performance is on par with the nVidia compiler.

### C Language Changes in Clang

#### C1X Feature Support

Clang 3.0 adds support for the `_Alignas`, `_Generic`, and `_Static_assert` keywords, drafted for inclusion in the next C standard, which is provisionally known as C1X. Use `-std=c1x` or `-std=gnu1x` to enable support for the new language standard. These features are backwards-compatible and are available as an extension in all language modes.

### C++ Language Changes in Clang

#### C++11 Feature Support

Clang 3.0 adds support for more of the language features added in the latest ISO C++ standard, C++ 2011. Use `-std=c++11` or `-std=gnu++11` to enable support for these features. The following are now considered to be of production quality:

- Range-based `for` loops
- Alias declarations (a new syntax for `typedef` declarations), including their `template` forms
- Specifying default values for class data members within a class definition
- Constructors delegating to other constructors of the same class
- The `override` context-sensitive keyword for virtual member function declarations
- Explicitly generating default function definitions with `= default`
- The `nullptr` keyword, and the corresponding type
- Raw string literals with arbitary delimiters (for instance, `R"delim(str"ing)delim"`)
- Unicode string literals (for instance, `U"\u1234"`) and the `char16_t` and `char32_t` built-in types
- `noexcept` expressions and the `noexcept` specifier on function declarations
- `alignof` expressions and the `alignas` specifier on variable declarations
- A full set of type traits, sufficient to support C++11 standard libraries

All warning and language selection flags which previously accepted `c++0x` now accept `c++11`. The old `c++0x` form remains as an alias.

### Objective-C Language Changes in Clang

Clang 3.0 introduces several new Objective-C language features and improvements.

#### Objective-C Automatic Reference Counting

ARC provides automated memory management for Objective-C programs that is compatible with existing retain/release code. ARC is carefully built to be a reliable programming model that errs on the side of producing a compiler error instead of silently producing a runtime memory problem. ARC automates Objective-C objects, not malloc data, file descriptors, CoreFoundation datatypes or anything else. For more details, see the full specification.

#### Objective-C Related Result Types / Instance Types

Allows declaring new methods which follow the Cocoa conventions for methods such as `init` which always return objects that are an instance of the receiving class's type. For more details, see the language extension documentation.

### Internal API Changes

These are major API changes that have happened since the 2.9 release of Clang. If upgrading an external codebase that uses Clang as a library, this section should help get you past the largest hurdles of upgrading.

#### Switched terminology from "instantiation" to "expansion" for macros

A great deal of comments and code changes fell out of this, but also every API relating to macros with the word "instantiation" (or some variant thereof) was renamed. An incomplete list of the most note-worthy ones is here:

- `MacroInstantiation` became `MacroExpansion`
- `SourceManager::getInstantiationLoc` became `SourceManager::getExpansionLoc`
- `SourceManager::getInstantiationRange` became `SourceManager::getExpansionRange`
- `SourceManager::getImmediateInstantiationRange` became `SourceManager::getImmediateExpansionRange`
- `SourceManager::getDecomposedInstantiationLoc` became `SourceManager::getDecomposedExpansionLoc`
- `SourceManager::getInstantiationColumnNumber` became `SourceManager::getExpansionColumnNumber`
- `SourceManager::getInstantiationLineNumber` became `SourceManager::getExpansionLineNumber`

#### Diagnostic class names were shuffled

- `Diagnostic` became `DiagnosticEngine`
- `DiagnosticClient` became `DiagnosticConsumer`
- `DiagnosticInfo` became `Diagnostic`

Subclasses of `DiagnosticConsumer` were also then renamed to end with `Consumer`.

## Significant Known Problems

## Additional Information

A wide variety of additional information is available on the Clang web page. The web page contains versions of the API documentation which are up-to-date with the Subversion version of the source code. You can access versions of these documents specific to this release by going into the "`clang/doc/`" directory in the Clang tree.

If you have any questions or comments about Clang, please feel free to contact us via the mailing list.