Reduce some false-positive warnings from GCC to warnings with -Werror

This also works around some of the same warnings. These are known bugs
in GCC 11+ and GCC 13.x.
This commit is contained in:
Tim Wojtulewicz 2025-06-05 15:36:38 -07:00
parent cd356ce45d
commit 57a3c733d1
6 changed files with 30 additions and 22 deletions

View file

@ -192,7 +192,7 @@ if (MSVC)
# TODO: This is disabled for now because there a bunch of known
# compiler warnings on Windows that we don't have good fixes for.
#set(WERROR_FLAG "/WX")
#set(WERROR_FLAG "/WX")
#set(WNOERROR_FLAG "/WX:NO")
endif ()
# Always build binpac in static mode if building on Windows
@ -202,6 +202,20 @@ else ()
include(GNUInstallDirs)
if (BUILD_WITH_WERROR)
set(WERROR_FLAG "-Werror")
set(WNOERROR_FLAG "-Wno-error")
# With versions >=13.0 GCC gained `-Warray-bounds` which reports false
# positives, see e.g., https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111273.
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
list(APPEND WERROR_FLAG "-Wno-error=array-bounds")
endif ()
# With versions >=11.0 GCC is returning false positives for -Wrestrict. See
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100366. It's more prevalent
# building with -std=c++20.
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
list(APPEND WERROR_FLAG "-Wno-error=restrict")
endif ()
endif ()
endif ()

View file

@ -41,18 +41,8 @@ set(BISON_FLAGS "--debug")
if (MSVC)
set(SIGN_COMPARE_FLAG "/wd4018")
if (BUILD_WITH_WERROR)
# TODO: This is disabled for now because there a bunch of known
# compiler warnings on Windows that we don't have good fixes for.
#set(WERROR_FLAG "/WX")
#set(WNOERROR_FLAG "/WX:NO")
endif ()
else ()
set(SIGN_COMPARE_FLAG "-Wno-sign-compare")
if (BUILD_WITH_WERROR)
set(WERROR_FLAG "-Werror")
set(WNOERROR_FLAG "-Wno-error")
endif ()
endif ()
# Rule parser/scanner

View file

@ -121,15 +121,15 @@ bool Ascii::OpenFile() {
fname = Info().source;
if ( fname.front() != '/' && ! path_prefix.empty() ) {
string path = path_prefix;
std::size_t last = path.find_last_not_of('/');
std::size_t last = path_prefix.find_last_not_of('/');
string path;
if ( last == string::npos ) // Nothing but slashes -- weird but ok...
path = "/";
else
path.erase(last + 1);
path = path_prefix.substr(0, last + 1);
fname = path + "/" + fname;
fname = util::fmt("%s/%s", path.c_str(), fname.c_str());
}
file.open(fname);

View file

@ -95,15 +95,15 @@ bool Binary::DoInit(const ReaderInfo& info, int num_fields, const Field* const*
// Handle path-prefixing. See similar logic in Ascii::OpenFile().
if ( fname.front() != '/' && ! path_prefix.empty() ) {
string path = path_prefix;
std::size_t last = path.find_last_not_of('/');
std::size_t last = path_prefix.find_last_not_of('/');
string path;
if ( last == string::npos ) // Nothing but slashes -- weird but ok...
path = "/";
else
path.erase(last + 1);
path = path_prefix.substr(0, last + 1);
fname = path + "/" + fname;
fname = util::fmt("%s/%s", path.c_str(), fname.c_str());
}
if ( ! OpenInput() )

View file

@ -40,8 +40,10 @@ std::string ZAMLocInfo::Describe(bool include_lines) const {
if ( include_lines ) {
desc += ";" + func_name + ":" + std::to_string(loc->FirstLine());
if ( loc->LastLine() > loc->FirstLine() )
desc += "-" + std::to_string(loc->LastLine());
if ( loc->LastLine() > loc->FirstLine() ) {
desc.append("-");
desc.append(std::to_string(loc->LastLine()));
}
}
}

View file

@ -368,7 +368,9 @@ void PackageTarget::DoGenerate() const {
for ( const auto& [pkg, info_vec] : pkg_manifest ) {
string header = util::fmt("Package: %s", pkg->Name().c_str());
header += "\n" + string(header.size(), '=');
auto header_size = header.size();
header.append("\n");
header.append(string(header_size, '='));
fprintf(file.f, "%s\n\n", header.c_str());