Skip to content

Commit

Permalink
Deal with some gcc-10 warnings and clang-10
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed May 31, 2020
1 parent 46dd015 commit 3452073
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 21 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
- Minor change of the proto wire format (extension w/ deprecation) to
allow distinction between empty and unset/equal effective keywords
- Manpage typo fixes, and clarify that --proto is setting independent
- The second part of the eix-0.34.3 patch was not in the repo.
- Deal with some new gcc-10 warnings and clang-10
- Put originally missing second part of eix-0.34.3 patch into repo

*eix-0.34.3
Martin Väth <martin at mvath.de>:
Expand Down
9 changes: 9 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,18 @@
/* Define if cache method sqlite is wanted */
#undef WITH_SQLITE

/* Define if GCC diagnostic -Wsuggest-attribute=const can be used */
#undef WSUGGEST_ATTRIBUTE_CONST

/* Define if GCC diagnostic -Wsuggest-attribute=pure can be used */
#undef WSUGGEST_ATTRIBUTE_PURE

/* Define if GCC diagnostic -Wsuggest-final-methods can be used */
#undef WSUGGEST_FINAL_METHODS

/* Define if GCC diagnostic -Wzero-as-null-pointer-constant can be used */
#undef WZERO_AS_NULL_POINTER_CONSTANT

/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
Expand Down
87 changes: 84 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ dnl -Wzero-as-null-pointer-constant makes sense only with new dialects
MV_ADDFLAGS([my_cxxadd], [CXXFLAGS], [AC_COMPILE_IFELSE], [ \
-fno-common \
-funsigned-char \
-fdirectives-only \
-ftracer \
-fconcepts \
], [$my_cxxfatal], [$CPPFLAGS], [:])
Expand All @@ -478,7 +477,7 @@ dnl -Wzero-as-null-pointer-constant makes sense only with new dialects
-Wmissing-include-dirs \
-Wswitch-default \
-Wstrict-aliasing=1 \
-Wstrict-overflow=5 \
-Wstrict-overflow \
-Wfloat-equal \
-Wundef \
-Wshadow \
Expand Down Expand Up @@ -534,7 +533,6 @@ dnl -Wzero-as-null-pointer-constant makes sense only with new dialects
-Wduplicated-branches \
-Wduplicated-cond \
-Wstringop-truncation \
-Wno-c++1z-extensions \
], [$my_cxxfatal], [], [:])
MV_ADDFLAGS([my_cxxadd], [CXXFLAGS], [AC_COMPILE_IFELSE], [ \
-Wcast-align=strict \
Expand Down Expand Up @@ -1032,6 +1030,89 @@ AS_IF([$wsuggest_final_methods],
[1],
[Define if GCC diagnostic -Wsuggest-final-methods can be used])])

# Check if _Pragma("GCC diagnostic \"-Wzero-as-null-pointer-constant\"") can be used
AC_MSG_CHECKING([whether pragma GCC diagnostic -Wzero-as-null-pointer-constant can be used])
MV_RUN_IFELSE_LINK([AC_LANG_PROGRAM([[
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x, y) GCC_DIAG_STR(x ## y)
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W, x))
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
static const char *f(const char *a) {
return a;
}
]], [[
GCC_DIAG_OFF(zero-as-null-pointer-constant)
return (f(0) == 0) ? 0 : 1;
GCC_DIAG_ON(zero-as-null-pointer-constant)
]])],
[MV_MSG_RESULT([yes])
AS_VAR_SET([wzero_as_null_pointer_constant], [:])],
[MV_MSG_RESULT([no])
AS_VAR_SET([wzero_as_null_pointer_constant], [false])])
AS_IF([$wzero_as_null_pointer_constant],
[AC_DEFINE([WZERO_AS_NULL_POINTER_CONSTANT],
[1],
[Define if GCC diagnostic -Wzero-as-null-pointer-constant can be used])])

# Check if _Pragma("GCC diagnostic \"-Wsuggest-attribute=const\"") can be used
AC_MSG_CHECKING([whether pragma GCC diagnostic -Wsuggest-attribute=const can be used])
MV_RUN_IFELSE_LINK([AC_LANG_PROGRAM([[
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x, y) GCC_DIAG_STR(x ## y)
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W, x))
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
GCC_DIAG_OFF(suggest-attribute=const)
int f();
int f() {
return 0;
}
GCC_DIAG_ON(suggest-attribute=const)
]], [[
return f();
]])],
[MV_MSG_RESULT([yes])
AS_VAR_SET([wsuggest_attribute_const], [:])],
[MV_MSG_RESULT([no])
AS_VAR_SET([wsuggest_attribute_const], [false])])
AS_IF([$wsuggest_attribute_const],
[AC_DEFINE([WSUGGEST_ATTRIBUTE_CONST],
[1],
[Define if GCC diagnostic -Wsuggest-attribute=const can be used])])

# Check if _Pragma("GCC diagnostic \"-Wsuggest-attribute=pure\"") can be used
AC_MSG_CHECKING([whether pragma GCC diagnostic -Wsuggest-attribute=pure can be used])
MV_RUN_IFELSE_LINK([AC_LANG_PROGRAM([[
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x, y) GCC_DIAG_STR(x ## y)
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W, x))
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
GCC_DIAG_OFF(suggest-attribute=pure)
int f();
int f() {
return 0;
}
GCC_DIAG_ON(suggest-attribute=pure)
]], [[
return f();
]])],
[MV_MSG_RESULT([yes])
AS_VAR_SET([wsuggest_attribute_pure], [:])],
[MV_MSG_RESULT([no])
AS_VAR_SET([wsuggest_attribute_pure], [false])])
AS_IF([$wsuggest_attribute_pure],
[AC_DEFINE([WSUGGEST_ATTRIBUTE_PURE],
[1],
[Define if GCC diagnostic -Wsuggest-attribute=pure can be used])])

# Check if _Pragma("GCC diagnostic \"-Wgnu-statement-expression\"") can be used in macro
AC_MSG_CHECKING([whether pragma GCC diagnostic -Wgnu-statement-expression can be used in macro])
MV_RUN_IFELSE_LINK([AC_LANG_PROGRAM([[
Expand Down
5 changes: 2 additions & 3 deletions contrib/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ SetCcache() {
ccache -C
}

clang_cxx=`PATH=${PATH-}${PATH:+:}/usr/lib/llvm/*/bin command -v clang++ 2>/dev/null` \
&& [ -n "${clang_cxx:++}" ] && clang=: || clang=false
command -v clang++ >/dev/null 2>&1 && clang=: || clang=false

meson=false
remove_builddir=false
Expand Down Expand Up @@ -274,7 +273,7 @@ then unset CFLAGS CXXFLAGS LDFLAGS CPPFLAGS CXX
CXX=`portageq envvar CXX`
export CFLAGS CXXFLAGS LDFLAGS CPPFLAGS
if $clang
then CXX=$clang_cxx
then CXX=clang++
FilterClang
fi
[ -z "$CXX" ] || export CXX
Expand Down
71 changes: 68 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ if warnings
cxxflags_opt += [
[ '-fno-common' ],
[ '-funsigned-char' ],
[ '-fdirectives-only' ],
[ '-ftracer' ],
[ '-fconcepts' ],
[ '-Wpedantic' ],
Expand All @@ -400,7 +399,7 @@ if warnings
[ '-Wmissing-include-dirs' ],
[ '-Wswitch-default' ],
[ '-Wstrict-aliasing=1' ],
[ '-Wstrict-overflow=5' ],
[ '-Wstrict-overflow' ],
[ '-Wfloat-equal' ],
[ '-Wundef' ],
[ '-Wshadow' ],
Expand Down Expand Up @@ -459,7 +458,6 @@ if warnings
[ '-Wduplicated-branches' ],
[ '-Wduplicated-cond' ],
[ '-Wstringop-truncation' ],
[ '-Wno-c++1z-extensions' ],
# [ '-Weverything' ],
# [ '-Wno-unknown-warning-option' ],
# [ '-fmem-report' ],
Expand Down Expand Up @@ -915,6 +913,73 @@ message('Wsuggest-final-methods: ' + wsuggest_final_methods.to_string())
conf.set('WSUGGEST_FINAL_METHODS', wsuggest_final_methods,
description : 'Define if GCC diagnostic -Wsuggest-final-methods can be used')

wzero_as_null_pointer_constant = cxx.links('''
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x, y) GCC_DIAG_STR(x ## y)
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W, x))
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
static const char *f(const char *a) {
return a;
}
int main() {
GCC_DIAG_OFF(zero-as-null-pointer-constant)
return (f(0) == 0) ? 0 : 1;
GCC_DIAG_ON(zero-as-null-pointer-constant)
}
''', args : flags_fatal)
message('Wzero-as-null-pointer-constant: ' + wzero_as_null_pointer_constant.to_string())
conf.set('WZERO_AS_NULL_POINTER_CONSTANT', wzero_as_null_pointer_constant,
description : 'Define if GCC diagnostic -Wzero-as-null-pointer-constant can be used')

wsuggest_attribute_const = cxx.links('''
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x, y) GCC_DIAG_STR(x ## y)
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W, x))
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
GCC_DIAG_OFF(suggest-attribute=const)
int f();
int f() {
return 0;
}
int main() {
GCC_DIAG_OFF(suggest-attribute=const)
return f();
GCC_DIAG_ON(suggest-attribute=const)
}
''', args : flags_fatal)
message('Wsuggest-attribute=const: ' + wzero_as_null_pointer_constant.to_string())
conf.set('WSUGGEST_ATTRIBUTE_CONST', wsuggest_attribute_const,
description : 'Define if GCC diagnostic -Wsuggest-attribute=const can be used')

wsuggest_attribute_pure = cxx.links('''
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x, y) GCC_DIAG_STR(x ## y)
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W, x))
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
GCC_DIAG_OFF(suggest-attribute=pure)
int f();
int f() {
return 0;
}
int main() {
GCC_DIAG_OFF(suggest-attribute=pure)
return f();
GCC_DIAG_ON(suggest-attribute=pure)
}
''', args : flags_fatal)
message('Wsuggest-attribute=pure: ' + wzero_as_null_pointer_constant.to_string())
conf.set('WSUGGEST_ATTRIBUTE_PURE', wsuggest_attribute_pure,
description : 'Define if GCC diagnostic -Wsuggest-attribute=pure can be used')

wgnu_statement_expression = cxx.links('''
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x, y) GCC_DIAG_STR(x ## y)
Expand Down
3 changes: 3 additions & 0 deletions src/database/header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void DBHeader::get_overlay_vector(set<ExtendedVersion::Overlay> *overlayset, con
}
}

WSUGGEST_ATTRIBUTE_PURE_OFF
// Attribute pure can cause subtle errors here
bool DBHeader::isCurrent() const {
for(const DBVersion *acc(accept); *acc != 0; ++acc) {
if(version == *acc) {
Expand All @@ -147,3 +149,4 @@ bool DBHeader::isCurrent() const {
}
return false;
}
WSUGGEST_ATTRIBUTE_PURE_ON
2 changes: 1 addition & 1 deletion src/eixTk/argsreader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ GCC_DIAG_ON(sign-conversion)
foldAndRemove(opt_table);
}

eix::TinyUnsigned ArgumentReader::numargs(const Option::Type opt_type) {
eix::TinyUnsigned ArgumentReader::numargs(Option::Type opt_type) {
switch(opt_type) {
case Option::STRING:
case Option::STRING_OPTIONAL:
Expand Down
2 changes: 1 addition & 1 deletion src/eixTk/argsreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ArgumentReader : public std::vector<Parameter> {
/**
@return number of args for opt
**/
ATTRIBUTE_PURE static eix::TinyUnsigned numargs(Option::Type opt_type);
ATTRIBUTE_CONST static eix::TinyUnsigned numargs(Option::Type opt_type);

/**
Fold parameter-list so that a option with an arguments has its argument set
Expand Down
26 changes: 25 additions & 1 deletion src/eixTk/diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,33 @@
#define WSUGGEST_FINAL_METHODS_ON
#endif

#ifdef WZERO_AS_NULL_POINTER_CONSTANT
#define WZERO_AS_NULL_POINTER_CONSTANT_OFF GCC_DIAG_OFF(zero-as-null-pointer-constant)
#define WZERO_AS_NULL_POINTER_CONSTANT_ON GCC_DIAG_ON(zero-as-null-pointer-constant)
#else
#define WZERO_AS_NULL_POINTER_CONSTANT_OFF
#define WZERO_AS_NULL_POINTER_CONSTANT_ON
#endif

#ifdef WSUGGEST_ATTRIBUTE_CONST
#define WSUGGEST_ATTRIBUTE_CONST_OFF GCC_DIAG_OFF(suggest-attribute=const)
#define WSUGGEST_ATTRIBUTE_CONST_ON GCC_DIAG_ON(suggest-attribute=const)
#else
#define WSUGGEST_ATTRIBUTE_CONST_OFF
#define WSUGGEST_ATTRIBUTE_CONST_ON
#endif

#ifdef WSUGGEST_ATTRIBUTE_PURE
#define WSUGGEST_ATTRIBUTE_PURE_OFF GCC_DIAG_OFF(suggest-attribute=pure)
#define WSUGGEST_ATTRIBUTE_PURE_ON GCC_DIAG_ON(suggest-attribute=pure)
#else
#define WSUGGEST_ATTRIBUTE_PURE_OFF
#define WSUGGEST_ATTRIBUTE_PURE_ON
#endif

#ifdef WGNU_STATEMENT_EXPRESSION
#define WGNU_STATEMENT_EXPRESSION_OFF GCC_DIAG_OFF(gnu-statement-expression)
#define WGNU_STATEMENT_EXPRESSION_ON GCC_DIAG_OFF(gnu-statement-expression)
#define WGNU_STATEMENT_EXPRESSION_ON GCC_DIAG_ON(gnu-statement-expression)
#else
#define WGNU_STATEMENT_EXPRESSION_OFF
#define WGNU_STATEMENT_EXPRESSION_ON
Expand Down
9 changes: 9 additions & 0 deletions src/eixTk/stringlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "eixTk/dialect.h"
#endif
#endif
#include "eixTk/diagnostics.h"
#include "eixTk/null.h"
#include "eixTk/stringtypes.h"

Expand Down Expand Up @@ -76,19 +77,27 @@ class StringListContent {
};

inline static bool operator<(const StringListContent& a, const StringListContent& b) {
WZERO_AS_NULL_POINTER_CONSTANT_OFF
return (a.m_list < b.m_list);
WZERO_AS_NULL_POINTER_CONSTANT_ON
}

inline static bool operator>(const StringListContent& a, const StringListContent& b) {
WZERO_AS_NULL_POINTER_CONSTANT_OFF
return (a.m_list > b.m_list);
WZERO_AS_NULL_POINTER_CONSTANT_ON
}

inline static bool operator<=(const StringListContent& a, const StringListContent& b) {
WZERO_AS_NULL_POINTER_CONSTANT_OFF
return (a.m_list <= b.m_list);
WZERO_AS_NULL_POINTER_CONSTANT_ON
}

inline static bool operator>=(const StringListContent& a, const StringListContent& b) {
WZERO_AS_NULL_POINTER_CONSTANT_OFF
return (a.m_list >= b.m_list);
WZERO_AS_NULL_POINTER_CONSTANT_ON
}

inline static bool operator==(const StringListContent& a, const StringListContent& b) {
Expand Down
8 changes: 8 additions & 0 deletions src/output/eix-proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@

#ifdef WITH_PROTOBUF
#include "eixTk/diagnostics.h"
WSUGGEST_ATTRIBUTE_PURE_OFF
WSUGGEST_ATTRIBUTE_CONST_OFF
WSUGGEST_FINAL_METHODS_OFF
GCC_DIAG_OFF(sign-conversion)

#include "output/eix.pb.cc" // NOLINT(build/include)

GCC_DIAG_ON(sign-conversion)
WSUGGEST_FINAL_METHODS_ON
WSUGGEST_ATTRIBUTE_CONST_ON
WSUGGEST_ATTRIBUTE_PURE_ON
#endif
3 changes: 3 additions & 0 deletions src/output/print-proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
#endif

#ifdef WITH_PROTOBUF
#include "eixTk/dialect.h"
#include "eixTk/likely.h"
#include "eixTk/null.h"
#include "eixTk/stringtypes.h"
#include "eixTk/unordered_set.h"
WSUGGEST_FINAL_METHODS_OFF
#include "output/eix.pb.h"
WSUGGEST_FINAL_METHODS_ON
#include "output/formatstring.h"
#include "portage/basicversion.h"
#include "portage/depend.h"
Expand Down
Loading

0 comments on commit 3452073

Please sign in to comment.