From 3401cf879f6d49014b031ed6879b84550b9672c7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 12 Jul 2009 21:22:10 +0000 Subject: [PATCH] document the diagnostics pragmas, patch by Louis Gerbarg! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75432 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/UsersManual.html | 64 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/docs/UsersManual.html b/docs/UsersManual.html index ab341150e3..8215849894 100644 --- a/docs/UsersManual.html +++ b/docs/UsersManual.html @@ -33,6 +33,12 @@ td {
  • Language and Target-Independent Features
  • @@ -362,7 +368,7 @@ by commenting them out.

    Clang provides a number of ways to control which code constructs cause it to emit errors and warning messages, and how they are displayed to the console.

    -

    Controlling How Clang Displays Diagnostics

    +

    Controlling How Clang Displays Diagnostics

    When Clang emits a diagnostic, it includes rich information in the output, and gives you fine-grain control over which information is printed. Clang has @@ -394,18 +400,64 @@ it:

    For more information please see Formatting of Diagnostics.

    -

    Controlling Which Diagnostics Clang Generates

    +

    Diagnostic Mappings

    -

    mappings: ignore, note, warning, error, fatal

    +

    All diagnostics are mapped into one of these 5 classes:

    -The two major classes are control from the command line and control via pragmas -in your code.

    +

    +

    Controlling Diagnostics via Command Line Flags

    -W flags, -pedantic, etc

    -

    pragma GCC diagnostic

    +

    Controlling Diagnostics via Pragmas

    + +

    Clang can also control what diagnostics are enabled through the use of +pragmas in the source code. This is useful for turning off specific warnings +in a section of source code. Clang supports GCC's pragma for compatibility +with existing source code, as well as several extensions.

    + +

    The pragma may control any warning that can be used from the command line. +Warnings may be set to ignored, warning, error, or fatal. The following +example code will tell Clang or GCC to ignore the -Wall warnings:

    + +
    +#pragma GCC diagnostic ignored "-Wall"
    +
    + +

    In addition to all of the functionality of provided by GCC's pragma, Clang +also allows you to push and pop the current warning state. This is particularly +useful when writing a header file that will be compiled by other people, because +you don't know what warning flags they build with.

    + +

    In the below example +-Wmultichar is ignored for only a single line of code, after which the +diagnostics return to whatever state had previously existed.

    + +
    +#pragma clang diagnostic push
    +#pragma clang diagnostic ignored "-Wmultichar"
    +
    +char b = 'df'; // no warning.
    +
    +#pragma clang diagnostic pop
    +
    + +

    The push and pop pragmas will save and restore the full diagnostic state of +the compiler, regardless of how it was set. That means that it is possible to +use push and pop around GCC compatible diagnostics and Clang will push and pop +them appropriately, while GCC will ignore the pushes and pops as unknown +pragmas. It should be noted that while Clang supports the GCC pragma, Clang and +GCC do not support the exact same set of warnings, so even when using GCC +compatible #pragmas there is no guarantee that they will have identical behaviour +on both compilers.

    Precompiled Headers

    -- 2.40.0