adjust for upstreaming of warn_unused attribute

The warn_unused attribute has been upstream to GCC and Clang, so use it if present.
Still warn about STL types if those do not use it yet (which is the status as of now).

Change-Id: I3c003e44c08d1d141e23bba38cf92e663a5ac353
This commit is contained in:
Luboš Luňák
2013-07-23 09:49:57 +02:00
parent 0d2a7adf4e
commit 92dfa82d2d
4 changed files with 44 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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