From 5ddbb6817610c64ce416f0517564f89ef9f25fe5 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 31 Jan 2013 14:08:36 +0100 Subject: [PATCH] Add the macro CGAL_USE_TYPE(), and a test for --- Installation/include/CGAL/use.h | 9 +++-- Installation/test/Installation/CMakeLists.txt | 2 ++ Installation/test/Installation/test_use_h.cpp | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Installation/test/Installation/test_use_h.cpp diff --git a/Installation/include/CGAL/use.h b/Installation/include/CGAL/use.h index fb513be303a..58cab5f54c6 100644 --- a/Installation/include/CGAL/use.h +++ b/Installation/include/CGAL/use.h @@ -25,10 +25,15 @@ namespace CGAL { namespace internal { template < typename T > inline void use(const T&) {} +template void use_type() {} + } } -// CGAL_USE() is a macro which aims at removing "variable is unused" warnings. - +/// CGAL_USE() is a macro which aims at removing "variable is unused" warnings. #define CGAL_USE(x) ::CGAL::internal::use(x) +/// CGAL_USE_TYPE() is a macro which aims at removing "typedef locally +/// defined but not used" warnings. +#define CGAL_USE_TYPE(T) ::CGAL::internal::use_type() + #endif // CGAL_USE_H diff --git a/Installation/test/Installation/CMakeLists.txt b/Installation/test/Installation/CMakeLists.txt index bece4754fec..9ff309b1d6a 100644 --- a/Installation/test/Installation/CMakeLists.txt +++ b/Installation/test/Installation/CMakeLists.txt @@ -42,6 +42,8 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "deprecation_warning.cpp" ) + create_single_source_cgal_program( "test_use_h.cpp" ) + create_link_to_program(CGAL) if ( WITH_CGAL_Core ) diff --git a/Installation/test/Installation/test_use_h.cpp b/Installation/test/Installation/test_use_h.cpp new file mode 100644 index 00000000000..a1a9f873f6c --- /dev/null +++ b/Installation/test/Installation/test_use_h.cpp @@ -0,0 +1,33 @@ +#include + +template +struct Foo { + typedef typename T::fake fake; + // Fake typedef to check that Foo is not instantiated. +}; + +int test_use_type() +{ + typedef Foo type; + + // If the following line is commented, g++-4.8 -Wall displays that + // warning: + // typedef ‘type’ locally defined but not used [-Wunused-local-typedefs] + CGAL_USE_TYPE(type); + + return 0; +} + +int test_use() { + int unused; + + // If the following line is commented, g++-4.8 -Wall displays that + // warning: + // unused variable ‘unused’ [-Wunused-variable] + CGAL_USE(unused); + return 0; +} + +int main() { + return test_use_type() + test_use(); +}