diff options
-rw-r--r-- | compilerplugins/clang/unusedvariablecheck.cxx | 9 | ||||
-rw-r--r-- | config_host/config_global.h.in | 4 | ||||
-rw-r--r-- | configure.ac | 28 | ||||
-rw-r--r-- | include/sal/types.h | 6 |
4 files changed, 44 insertions, 3 deletions
diff --git a/compilerplugins/clang/unusedvariablecheck.cxx b/compilerplugins/clang/unusedvariablecheck.cxx index a0763ac2f11d..86f405db0f7c 100644 --- a/compilerplugins/clang/unusedvariablecheck.cxx +++ b/compilerplugins/clang/unusedvariablecheck.cxx @@ -8,6 +8,13 @@ * */ +#include <config_global.h> + +// If there is support for warn_unused attribute even in STL classes, then there's +// no point in having this check enabled, otherwise keep it at least for STL +// (LO classes won't get duplicated warnings, as the attribute is different). +#if !HAVE_GCC_ATTRIBUTE_WARN_UNUSED_STL + #include "unusedvariablecheck.hxx" #include <clang/AST/Attr.h> @@ -101,3 +108,5 @@ bool UnusedVariableCheck::VisitVarDecl( const VarDecl* var ) static Plugin::Registration< UnusedVariableCheck > X( "unusedvariablecheck" ); } // namespace + +#endif diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in index 9b1b12a97c63..31f64e6ed54d 100644 --- a/config_host/config_global.h.in +++ b/config_host/config_global.h.in @@ -23,5 +23,9 @@ Any change in this header will cause a rebuild of almost everything. #define HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE 0 #define HAVE_THREADSAFE_STATICS 0 #define HAVE_SYSLOG_H 0 +/* Compiler supports __attribute__((warn_unused)). */ +#define HAVE_GCC_ATTRIBUTE_WARN_UNUSED 0 +/* C++ library uses __attribute__((warn_unused)) for basic types like std::string. */ +#define HAVE_GCC_ATTRIBUTE_WARN_UNUSED_STL 0 #endif diff --git a/configure.ac b/configure.ac index add4a6bbd8c8..1147e4dddf37 100644 --- a/configure.ac +++ b/configure.ac @@ -5668,6 +5668,34 @@ if test "$GCC" = "yes"; then AC_MSG_RESULT([yes]) ], [AC_MSG_RESULT([no])]) AC_LANG_POP([C++]) + + AC_MSG_CHECKING([whether $CXX supports __attribute__((warn_unused))]) + AC_LANG_PUSH([C++]) + save_CXXFLAGS=$CXXFLAGS + CXXFLAGS="$CFLAGS -Werror -Wunknown-pragmas" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + struct __attribute__((warn_unused)) dummy {}; + ])], [ + AC_DEFINE([HAVE_GCC_ATTRIBUTE_WARN_UNUSED],[1]) + AC_MSG_RESULT([yes]) + ], [AC_MSG_RESULT([no])]) + CXXFLAGS=$save_CXXFLAGS + AC_LANG_POP([C++]) + + AC_MSG_CHECKING([whether STL uses __attribute__((warn_unused))]) + AC_LANG_PUSH([C++]) + save_CXXFLAGS=$CXXFLAGS + CXXFLAGS="$CFLAGS -Werror -Wunused" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include <string> + void f() { std::string s; } + ])], [ + AC_MSG_RESULT([no]) + ], [ + AC_DEFINE([HAVE_GCC_ATTRIBUTE_WARN_UNUSED_STL],[1]) + AC_MSG_RESULT([yes])]) + CXXFLAGS=$save_CXXFLAGS + AC_LANG_POP([C++]) fi AC_SUBST(HAVE_GCC_NO_LONG_DOUBLE) diff --git a/include/sal/types.h b/include/sal/types.h index 070a3f29474a..9ce2cef8aa19 100644 --- a/include/sal/types.h +++ b/include/sal/types.h @@ -551,13 +551,13 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) { or external constructors or destructors. Classes marked with SAL_WARN_UNUSED will be warned about. - Currently implemented by a Clang compiler plugin. - @since LibreOffice 4.0 */ -#if defined __clang__ +#if HAVE_GCC_ATTRIBUTE_WARN_UNUSED +#define SAL_WARN_UNUSED __attribute__((warn_unused)) +#elif defined __clang__ #define SAL_WARN_UNUSED __attribute__((annotate("lo_warn_unused"))) #else #define SAL_WARN_UNUSED |