Improved deprecation_warning.h

-- Actually fail compilation even if CGAL_NO_DEPRECATION_WARNINGS is defined
-- An optional message can be passed through CGAL_DEPRECATED_MESSAGE_DETAILS
-- Print the replacement header in all cases, not just when warning about
   the deprecated header.
This commit is contained in:
Mael Rouxel-Labbé 2017-05-09 14:05:56 +02:00
parent c353f0f49c
commit 7cef85e107
1 changed files with 62 additions and 33 deletions

View File

@ -12,44 +12,69 @@
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Philipp Möller
// Author(s) : Philipp Möller, Mael Rouxel-Labbé
// Including this header will issue a warning during compilation or
// cause compilation to fail if CGAL_NO_DEPRECATED_CODE is defined.
// CGAL_DEPRECATED_HEADER and CGAL_REPLACEMENT_HEADER can be defined
// Including this header will cause compilation to fail
// if CGAL_NO_DEPRECATED_CODE is defined. If this is not the case, it will issue
// a warning during compilation unless CGAL_NO_DEPRECATION_WARNINGS.
// CGAL_DEPRECATED_HEADER, CGAL_REPLACEMENT_HEADER, and
// CGAL_DEPRECATED_MESSAGE_DETAILS can be defined
// to a string literal to customize the warning.
// CGAL_DEPRECATED_HEADER and CGAL_REPLACEMENT_HEADER are undefined,
// after the file is included.
// CGAL_DEPRECATED_HEADER, CGAL_REPLACEMENT_HEADER, and
// CGAL_DEPRECATED_MESSAGE_DETAILS are undefined after the file is included.
// The lack of an include guard is intentional and necessary.
#include <CGAL/assertions.h>
#ifndef CGAL_NO_DEPRECATION_WARNINGS
// whether to print Warning or Error
#if defined(CGAL_NO_DEPRECATED_CODE)
// No deprecated code.
CGAL_static_assertion_msg(false, "A deprecated header has been included and CGAL_NO_DEPRECATED_CODE is defined.");
#endif // CGAL_NO_DEPRECATED_CODE
// Build the message
#define CGAL_INTERNAL_DEPRECATED_MESSAGE "Warning: A deprecated header has been included."
#if defined(CGAL_DEPRECATED_HEADER) && defined(CGAL_REPLACEMENT_HEADER)
# undef CGAL_INTERNAL_DEPRECATED_MESSAGE
# define CGAL_INTERNAL_DEPRECATED_MESSAGE "Warning: The header " CGAL_DEPRECATED_HEADER " is deprecated. " \
"Please use " CGAL_REPLACEMENT_HEADER " instead."
#elif defined(CGAL_DEPRECATED_HEADER)
# undef CGAL_INTERNAL_DEPRECATED_MESSAGE
# define CGAL_INTERNAL_DEPRECATED_MESSAGE "Warning: The header " CGAL_DEPRECATED_HEADER " is deprecated."
# define CGAL_INTERNAL_DEPRECATED_MESSAGE_STATUS "Error: "
# define CGAL_INTERNAL_NO_DEPRECATED_CODE_MESSAGE " and CGAL_NO_DEPRECATED_CODE is defined."
#else
# define CGAL_INTERNAL_DEPRECATED_MESSAGE_STATUS "Warning: "
# define CGAL_INTERNAL_NO_DEPRECATED_CODE_MESSAGE "."
#endif
// don't trigger on NO_DEPRECATIOON_WARNINGS and don't trigger twice on NO_DEPRECATED_CODE
#if !defined(CGAL_NO_DEPRECATION_WARNINGS) && !defined(CGAL_NO_DEPRECATED_CODE)
// if the name of the deprecated header is given, print it
#if defined(CGAL_DEPRECATED_HEADER)
# define CGAL_INTERNAL_DEPRECATED_MESSAGE_DEPRECATED_HEADER \
"The header `" CGAL_DEPRECATED_HEADER "` is deprecated"
#else
# define CGAL_INTERNAL_DEPRECATED_MESSAGE_DEPRECATED_HEADER \
"A deprecated header has been included"
#endif
// if a replacement header is given, print it
#if defined(CGAL_REPLACEMENT_HEADER)
# define CGAL_INTERNAL_DEPRECATED_MESSAGE_HEADERS \
CGAL_INTERNAL_DEPRECATED_MESSAGE_DEPRECATED_HEADER \
CGAL_INTERNAL_NO_DEPRECATED_CODE_MESSAGE \
" Please use `" CGAL_REPLACEMENT_HEADER "` instead.\n"
#else
# define CGAL_INTERNAL_DEPRECATED_MESSAGE_HEADERS \
CGAL_INTERNAL_DEPRECATED_MESSAGE_DEPRECATED_HEADER \
CGAL_INTERNAL_NO_DEPRECATED_CODE_MESSAGE "\n"
#endif
// if more details are given, print them
#if defined(CGAL_DEPRECATED_MESSAGE_DETAILS)
# define CGAL_INTERNAL_DEPRECATED_MESSAGE \
CGAL_INTERNAL_DEPRECATED_MESSAGE_STATUS \
CGAL_INTERNAL_DEPRECATED_MESSAGE_HEADERS \
"Additional information: "\
CGAL_DEPRECATED_MESSAGE_DETAILS
#else
# define CGAL_INTERNAL_DEPRECATED_MESSAGE \
CGAL_INTERNAL_DEPRECATED_MESSAGE_STATUS \
CGAL_INTERNAL_DEPRECATED_MESSAGE_HEADERS
#endif
#if defined(CGAL_NO_DEPRECATED_CODE) // No deprecated code.
CGAL_static_assertion_msg(false, CGAL_INTERNAL_DEPRECATED_MESSAGE);
#elif !defined(CGAL_NO_DEPRECATION_WARNINGS) // don't trigger on NO_DEPRECATION_WARNINGS
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__)
# pragma message (CGAL_INTERNAL_DEPRECATED_MESSAGE)
# elif defined(__GNUC__) || defined(__HP_aCC) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
@ -59,7 +84,15 @@ CGAL_static_assertion_msg(false, "A deprecated header has been included and CGAL
# endif //defined
#endif
#endif // CGAL_NO_DEPRECATION_WARNINGS
// those macros have been defined in all cases
#undef CGAL_INTERNAL_DEPRECATED_MESSAGE_STATUS
#undef CGAL_INTERNAL_DEPRECATED_MESSAGE_DEPRECATED_HEADER
#undef CGAL_INTERNAL_DEPRECATED_MESSAGE_HEADERS
#undef CGAL_INTERNAL_DEPRECATED_MESSAGE
#if defined(CGAL_DEPRECATED_MESSAGE_DETAILS)
# undef CGAL_DEPRECATED_MESSAGE_DETAILS
#endif
#if defined(CGAL_DEPRECATED_HEADER)
# undef CGAL_DEPRECATED_HEADER
@ -68,7 +101,3 @@ CGAL_static_assertion_msg(false, "A deprecated header has been included and CGAL
#if defined(CGAL_REPLACEMENT_HEADER)
# undef CGAL_REPLACEMENT_HEADER
#endif
#if defined(CGAL_INTERNAL_DEPRECATED_MESSAGE)
# undef CGAL_INTERNAL_DEPRECATED_MESSAGE
#endif