4.6.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
fcppt.preprocessor

Description

Macros for controlling warnings and printing messages.

Controlling Warnings

In general, you should enable as many warnings as possible for your projects. However, sometimes you might want to disable a warning only in a part of your code. Another problem arises when other libraries like Boost cause you warnings you cannot fix.

To disable warnings in a scope, fcppt provides the following macros:

FCPPT_PP_PUSH_WARNING

Pushes the warning stack

FCPPT_PP_POP_WARNING

Pops the warning stack

FCPPT_PP_DISABLE_GCC_WARNING

Disables a given warning option only on gcc like compilers

FCPPT_PP_DISABLE_VC_WARNING
Disables a given warning option only on VC++

To minimize the scope where warnings are disabled, you should always start with an FCPPT_PP_PUSH_WARNING , followed by disabling the warning(s). To close the scope, FCPPT_PP_POP_WARNING should be used.

Warning
These macros cannot be placed everywhere. You should only place them around statements or scopes. For example, placing them around an initialization list will not work.

The first example shows how to disable the this used in constructor initialization list warning for VC++.

struct outer;
struct inner
{
explicit inner(outer *) {}
};
struct outer
{
// Disable the warning that triggers when 'this' is used in the initialization
// list.
outer() : inner_(this) {}
private:
inner inner_;
};

The second example shows how to disable -Wold-style-cast warning for gcc.

float test()
{
// Here is a C macro from another library that uses a C style cast.
#define SOME_C_LIB_MACRO (float)(42)
// Disable old style cast warning
FCPPT_PP_DISABLE_GCC_WARNING(-Wold-style-cast)
return SOME_C_LIB_MACRO;
}

Printing messages

Printing compiler messages can be useful to print general diagnostics, todo or fixme messages.

fcppt provides FCPPT_PP_MESSAGE to do that. There are three more macros called FCPPT_PP_TODO , FCPPT_PP_FIXME and FCPPT_PP_WARNING , that print "TODO: ", "FIXME: " and "warning: " in front or their message, respectively.

Pragmas in macros

Pragmas are implementation-defined ways to instruct the compiler to do something special. The warning and message macros of fcppt are implemented by pragmas, for example. The problem with the pragma directive is that it cannot be embedded in a macro, like in the following code:

#define MY_MACRO #pragma something

Instead, fcppt provides a macro that can be used instead of the pragma directive, called FCPPT_PP_PRAGMA . The above example can then be written as:

#define MY_MACRO FCPPT_PP_PRAGMA(something)

Pretty printing

C++03 has FILE and LINE to print information about where a macro is invoked in a file. However, it is missing a FUNCTION macro that C99 (and now C++11) has. FCPPT_PP_FUNCTION fills in that gap. There is also FCPPT_PP_FILE that expands to the current file compatible with fcppt::string.

void some_function()
{
fcppt::io::cout() << FCPPT_PP_FILE << FCPPT_TEXT(':') << __LINE__ << FCPPT_TEXT(": ")
}

Header files

Header file Description
disable_gcc_warning.hpp Contains FCPPT_PP_DISABLE_GCC_WARNING
disable_vc_warning.hpp Contains FCPPT_PP_DISABLE_VC_WARNING
file.hpp Contains FCPPT_PP_FILE
fixme.hpp Contains FCPPT_PP_FIXME
function.hpp Contains FCPPT_PP_FUNCTION
message.hpp Contains FCPPT_PP_MESSAGE
pop_warning.hpp Contains FCPPT_PP_POP_WARNING
pragma.hpp Contains FCPPT_PP_PRAGMA
push_warning.hpp Contains FCPPT_PP_PUSH_WARNING
stringize.hpp Contains FCPPT_PP_STRINGIZE
todo.hpp Contains FCPPT_PP_TODO
warning.hpp Contains FCPPT_PP_WARNING

Macros

#define FCPPT_PP_DISABLE_CLANG_WARNING(warning_name)
 Disables a given clang warning (does nothing on other compilers)
 
#define FCPPT_PP_DISABLE_GCC_WARNING(warning_name)
 Disables a given gcc or clang warning (does nothing on other compilers)
 
#define FCPPT_PP_DISABLE_GNU_GCC_WARNING(warning_name)
 Disables a given gcc (which does not include clang here) warning (does nothing on other compilers)
 
#define FCPPT_PP_DISABLE_VC_WARNING(warning_number)
 Disables a given VC++ warning (does nothing on other compilers)
 
#define FCPPT_PP_FILE   fcppt::from_std_string(__FILE__)
 Prints the current file name.
 
#define FCPPT_PP_FIXME(message)
 Prints a FIXME compiler message.
 
#define FCPPT_PP_FUNCTION   FCPPT_PP_DETAIL_FUNCTION
 Pretty prints the current function name.
 
#define FCPPT_PP_MESSAGE(message)
 Prints a compiler message.
 
#define FCPPT_PP_POP_WARNING   FCPPT_PP_DETAIL_POP_WARNING
 Pops the current warning stack.
 
#define FCPPT_PP_PRAGMA(expr)
 A macro that expands to a pragma directive.
 
#define FCPPT_PP_PUSH_WARNING   FCPPT_PP_DETAIL_PUSH_WARNING
 Pushes the current warning stack.
 
#define FCPPT_PP_STRINGIZE(string)
 Creates a string from its macro argument.
 
#define FCPPT_PP_TODO(message)
 Prints a TODO compiler message.
 
#define FCPPT_PP_WARNING(message)
 Prints a warning compiler message.
 

Macro Definition Documentation

◆ FCPPT_PP_DISABLE_CLANG_WARNING

#define FCPPT_PP_DISABLE_CLANG_WARNING ( warning_name)
Value:
FCPPT_PP_DETAIL_DISABLE_CLANG_WARNING(\
warning_name\
)

Disables a given clang warning (does nothing on other compilers)

Disables the clang warning denoted by warning_name

Parameters
warning_nameThe full command line option of the warning to disable
See also
Controlling Warnings

◆ FCPPT_PP_DISABLE_GCC_WARNING

#define FCPPT_PP_DISABLE_GCC_WARNING ( warning_name)
Value:
FCPPT_PP_DETAIL_DISABLE_GCC_WARNING(\
warning_name\
)

Disables a given gcc or clang warning (does nothing on other compilers)

Disables the gcc warning denoted by warning_name

Parameters
warning_nameThe full command line option of the warning to disable
See also
Controlling Warnings

◆ FCPPT_PP_DISABLE_GNU_GCC_WARNING

#define FCPPT_PP_DISABLE_GNU_GCC_WARNING ( warning_name)
Value:
FCPPT_PP_DETAIL_DISABLE_GNU_GCC_WARNING(\
warning_name\
)

Disables a given gcc (which does not include clang here) warning (does nothing on other compilers)

Disables the gcc (not clang) warning denoted by warning_name

Parameters
warning_nameThe full command line option of the warning to disable
See also
Controlling Warnings

◆ FCPPT_PP_DISABLE_VC_WARNING

#define FCPPT_PP_DISABLE_VC_WARNING ( warning_number)
Value:
FCPPT_PP_DETAIL_DISABLE_VC_WARNING(warning_number)

Disables a given VC++ warning (does nothing on other compilers)

Disables the VC++ warning denoted by warning_number

Parameters
warning_numberThe warning number to disable
See also
Controlling Warnings

◆ FCPPT_PP_FILE

#define FCPPT_PP_FILE   fcppt::from_std_string(__FILE__)

Prints the current file name.

It is equivalent to FILE except that it returns an rvalue that is suitable to use with fcppt::string.

◆ FCPPT_PP_FIXME

#define FCPPT_PP_FIXME ( message)
Value:
FCPPT_PP_MESSAGE("FIXME: " message)

Prints a FIXME compiler message.

Prints the compiler message "FIXME: " message.

Parameters
messageThe message should be a narrow string literal
See also
FCPPT_PP_MESSAGE

◆ FCPPT_PP_FUNCTION

#define FCPPT_PP_FUNCTION   FCPPT_PP_DETAIL_FUNCTION

Pretty prints the current function name.

If support for pretty function printing is available, this macro will expand to the name of the current function, either as a literal or as some other rvalue, depending on the compiler. The type of the function name is suitable to use with fcppt::string.

If there is no support for function printing, then this macro will always expand to an empty literal.

◆ FCPPT_PP_MESSAGE

#define FCPPT_PP_MESSAGE ( message)
Value:
FCPPT_PP_DETAIL_MESSAGE(message)

Prints a compiler message.

Intructs the compiler to print message. If there is no support for compiler messages, nothing will happen.

Parameters
messageThe message should be a narrow string literal

◆ FCPPT_PP_POP_WARNING

#define FCPPT_PP_POP_WARNING   FCPPT_PP_DETAIL_POP_WARNING

Pops the current warning stack.

Pops the stack of the current warning settings so that changes made since the last FCPPT_PP_PUSH_WARNING will be undone.

See also
Controlling Warnings

◆ FCPPT_PP_PRAGMA

#define FCPPT_PP_PRAGMA ( expr)
Value:
FCPPT_PP_DETAIL_PRAGMA(\
expr\
)

A macro that expands to a pragma directive.

Expands expr as if #pragma expr was written. This is useful to embed pragmas into macro definitions which is normally not possible.

Parameters
exprThe pragma expression

◆ FCPPT_PP_PUSH_WARNING

#define FCPPT_PP_PUSH_WARNING   FCPPT_PP_DETAIL_PUSH_WARNING

Pushes the current warning stack.

Pushes the stack of the current warning settings so that changes can be made which can later be undone by FCPPT_PP_POP_WARNING

See also
Controlling Warnings

◆ FCPPT_PP_STRINGIZE

#define FCPPT_PP_STRINGIZE ( string)
Value:
FCPPT_PP_DETAIL_STRINGIZE(string)

Creates a string from its macro argument.

Stringizes its macro argument so that it is suitable to use with fcppt::string.

Parameters
stringThe argument to stringize

◆ FCPPT_PP_TODO

#define FCPPT_PP_TODO ( message)
Value:
FCPPT_PP_MESSAGE("TODO: " message)

Prints a TODO compiler message.

Prints the compiler message "TODO: " message.

Parameters
messageThe message should be a narrow string literal
See also
FCPPT_PP_MESSAGE

◆ FCPPT_PP_WARNING

#define FCPPT_PP_WARNING ( message)
Value:
FCPPT_PP_MESSAGE("warning: " message)

Prints a warning compiler message.

Prints the compiler message "warning: " message. Note, that this is just a normal message and might not be interpreted by the compiler, IDE, etc. as a real warning.

Parameters
messageThe message should be a narrow string literal
See also
FCPPT_PP_MESSAGE