compilerplugins/clang/unusedvariablecheck.cxx |    9 ++++++++
 config_host/config_global.h.in                |    4 +++
 configure.ac                                  |   28 ++++++++++++++++++++++++++
 include/sal/types.h                           |    6 ++---
 4 files changed, 44 insertions(+), 3 deletions(-)

New commits:
commit 92dfa82d2d25f2acdee0a538bf15f1fac36c0ecf
Author: Luboš Luňák <l.lu...@suse.cz>
Date:   Tue Jul 23 09:49:57 2013 +0200

    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

diff --git a/compilerplugins/clang/unusedvariablecheck.cxx 
b/compilerplugins/clang/unusedvariablecheck.cxx
index a0763ac..86f405d 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 9b1b12a..31f64e6 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 add4a6b..1147e4d 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 070a3f29..9ce2cef 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
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to