4.6.0
Freundlich's C++ toolkit
|
Macros for controlling warnings and printing messages.
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:
Pushes the warning stack
Pops the warning stack
Disables a given warning option only on gcc like compilers
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.
The first example shows how to disable the this used in constructor initialization list warning for VC++.
The second example shows how to disable -Wold-style-cast
warning for gcc.
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 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:
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:
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.
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. | |
#define FCPPT_PP_DISABLE_CLANG_WARNING | ( | warning_name | ) |
Disables a given clang warning (does nothing on other compilers)
Disables the clang warning denoted by warning_name
warning_name | The full command line option of the warning to disable |
#define FCPPT_PP_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
warning_name | The full command line option of the warning to disable |
#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)
Disables the gcc (not clang) warning denoted by warning_name
warning_name | The full command line option of the warning to disable |
#define FCPPT_PP_DISABLE_VC_WARNING | ( | warning_number | ) |
Disables a given VC++ warning (does nothing on other compilers)
Disables the VC++ warning denoted by warning_number
warning_number | The warning number to disable |
#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.
#define FCPPT_PP_FIXME | ( | message | ) |
Prints a FIXME compiler message.
Prints the compiler message "FIXME: " message
.
message | The message should be a narrow string literal |
#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.
#define FCPPT_PP_MESSAGE | ( | message | ) |
Prints a compiler message.
Intructs the compiler to print message. If there is no support for compiler messages, nothing will happen.
message | The message should be a narrow string literal |
#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.
#define FCPPT_PP_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.
expr | The pragma expression |
#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
#define FCPPT_PP_STRINGIZE | ( | string | ) |
Creates a string from its macro argument.
Stringizes its macro argument so that it is suitable to use with fcppt::string.
string | The argument to stringize |
#define FCPPT_PP_TODO | ( | message | ) |
Prints a TODO compiler message.
Prints the compiler message "TODO: " message
.
message | The message should be a narrow string literal |
#define FCPPT_PP_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.
message | The message should be a narrow string literal |