Skip to content

Commit

Permalink
Squashed some clang-tidy warnings, slightly adjusted clang-tidy config (
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel authored Feb 28, 2025
1 parent 85fb949 commit ce6161c
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 255 deletions.
54 changes: 34 additions & 20 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
Checks: '
-*,
boost-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-narrowing-conversions,
clang-analyzer-*,
-clang-analyzer-cplusplus.NewDelete,
-clang-analyzer-cplusplus.NewDeleteLeaks,
misc-*,
-misc-definitions-in-headers,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
performance-*
'
Checks:
- '-*'
- 'boost-*'
# We use ranges where it suits us, but not everywhere.
- '-boost-use-ranges'
- 'bugprone-*'
# We have too much code violating this. Consider re-enabling in the future (nice to have)
- '-bugprone-easily-swappable-parameters'
# We should enable this, but we have some tricky cases to fix first
- '-bugprone-exception-escape'
# We have too much code violating this. Consider re-enabling in the future
- '-bugprone-narrowing-conversions'
# Sometimes, assignment in if make code more readable
- '-bugprone-assignment-in-if-condition'
- 'clang-analyzer-*'
- 'misc-*'
# We do allow using recursive functions
- '-misc-no-recursion'
# We have too much code violating this. Consider re-enabling in the future.
- '-misc-non-private-member-variables-in-classes'
- 'modernize-*'
# We have too much code violating this. Consider re-enabling in the future.
- '-modernize-avoid-c-arrays'
# We use nodiscard in some key classes, but it's a bit noisy to enable everywhere.
- '-modernize-use-nodiscard'
# We're not using trailing return types for regular functions
- '-modernize-use-trailing-return-type'
- 'performance-*'
# We use std::endl in some places, where we want to flush the stream
- '-performance-avoid-endl'

CheckOptions:
misc-include-cleaner.IgnoreHeaders: 'boost/.*;fontconfig/.*;glib.h'

WarningsAsErrors: ''
5 changes: 3 additions & 2 deletions src/Feature.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "Feature.h"

#include <cstdio>
#include <string>
#include <utility>

#include <boost/algorithm/string/join.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <utility>

#include "utils/exceptions.h"
#include "utils/printutils.h"

/**
Expand Down
1 change: 0 additions & 1 deletion src/Feature.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <cstdio>
#include <string>
#include <map>
#include <vector>
Expand Down
40 changes: 24 additions & 16 deletions src/FontCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,34 @@

#include "FontCache.h"

#include <cassert>
#include <cstdlib>
#include <cstdint>
#include <ctime>
#include <filesystem>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

#include <filesystem>
#include <boost/algorithm/string.hpp>
#include <string>
#include <utility>
#include <hb.h>
#include <fontconfig/fontconfig.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TYPES_H
#include FT_TRUETYPE_IDS_H

#include "platform/PlatformUtils.h"
#include "utils/printutils.h"
#include "utils/version_helper.h"

extern std::vector<std::string> librarypath;

std::vector<std::string> fontpath;

namespace fs = std::filesystem;

const std::string get_fontconfig_version()
std::string get_fontconfig_version()
{
const unsigned int version = FcGetVersion();

Expand All @@ -54,7 +62,7 @@ const std::string get_fontconfig_version()
return OpenSCAD::get_version_string(header_version, runtime_version);
}

const std::string get_harfbuzz_version()
std::string get_harfbuzz_version()
{
unsigned int major, minor, micro;
hb_version(&major, &minor, &micro);
Expand All @@ -64,7 +72,7 @@ const std::string get_harfbuzz_version()
return OpenSCAD::get_version_string(header_version, runtime_version);
}

const std::string get_freetype_version()
std::string get_freetype_version()
{
return FontCache::instance()->get_freetype_version();
}
Expand Down Expand Up @@ -128,7 +136,7 @@ FontCache::FontCache()
// If we've got a bundled fonts.conf, initialize fontconfig with our own config
// by overriding the built-in fontconfig path.
// For system installs and dev environments, we leave this alone
fs::path fontdir(PlatformUtils::resourcePath("fonts"));
const fs::path fontdir(PlatformUtils::resourcePath("fonts"));
if (fs::is_regular_file(fontdir / "fonts.conf")) {
auto abspath = fontdir.empty() ? fs::current_path() : fs::absolute(fontdir);
PlatformUtils::setenv("FONTCONFIG_PATH", (abspath.generic_string()).c_str(), 0);
Expand Down Expand Up @@ -167,7 +175,7 @@ FontCache::FontCache()
for (string_split_iterator it = boost::make_split_iterator(paths, boost::first_finder(sep, boost::is_iequal())); it != string_split_iterator(); ++it) {
const fs::path p(boost::copy_range<std::string>(*it));
if (fs::exists(p) && fs::is_directory(p)) {
std::string path = fs::absolute(p).string();
const std::string path = fs::absolute(p).string();
add_font_dir(path);
}
}
Expand Down Expand Up @@ -243,7 +251,7 @@ std::vector<uint32_t> FontCache::filter(const std::u32string& str) const
FcPattern *pattern = FcPatternCreate();
init_pattern(pattern);
FcCharSet *charSet = FcCharSetCreate();
for (char32_t a : str) {
for (const char32_t a : str) {
FcCharSetAddChar(charSet, a);
}
FcValue charSetValue;
Expand Down Expand Up @@ -287,11 +295,11 @@ FontInfoList *FontCache::list_fonts() const
FcValue style_value;
FcPatternGet(p, FC_STYLE, 0, &style_value);

std::string family((const char *) family_value.u.s);
std::string style((const char *) style_value.u.s);
std::string file((const char *) file_value.u.s);
const std::string family((const char *) family_value.u.s);
const std::string style((const char *) style_value.u.s);
const std::string file((const char *) file_value.u.s);

list->push_back(FontInfo(family, style, file, FcPatternHash(p)));
list->emplace_back(family, style, file, FcPatternHash(p));
}
FcFontSetDestroy(font_set);

Expand Down Expand Up @@ -405,7 +413,7 @@ FT_Face FontCache::find_face_fontconfig(const std::string& font) const
}

FT_Face face;
FT_Error error = FT_New_Face(this->library, (const char *) file_value.u.s, font_index.u.i, &face);
const FT_Error error = FT_New_Face(this->library, (const char *) file_value.u.s, font_index.u.i, &face);

FcPatternDestroy(pattern);
FcPatternDestroy(match);
Expand Down Expand Up @@ -460,7 +468,7 @@ bool FontCache::is_windows_symbol_font(const FT_Face& face) const
}

FT_UInt gindex;
FT_ULong charcode = FT_Get_First_Char(face, &gindex);
const FT_ULong charcode = FT_Get_First_Char(face, &gindex);
if ((gindex == 0) || (charcode < 0xf000)) {
return false;
}
Expand Down
16 changes: 7 additions & 9 deletions src/FontCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@
*/
#pragma once

#include <utility>
#include <cstdint>
#include <ctime>
#include <map>
#include <string>

#include <ctime>
#include <string>
#include <utility>
#include <vector>

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_IDS_H

#include <vector>
#include <string>
#include <fontconfig/fontconfig.h>

#include <hb.h>
#include <hb-ft.h>
std::string get_fontconfig_version();
std::string get_harfbuzz_version();
std::string get_freetype_version();

class FontInfo
{
Expand Down
54 changes: 29 additions & 25 deletions src/LibraryInfo.cc
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
#include "LibraryInfo.h"

#include <cstdlib>
#include <sstream>
#include <glib.h>
#include <string>
#include <vector>

#include "utils/version_check.h"
#include "platform/PlatformUtils.h"
#include "version.h"
#include "Feature.h"
#include <clipper2/clipper.version.h>
#include <Eigen/Core>
#include <glib.h>

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#ifndef OPENSCAD_NOGUI
#include <QtGlobal>
#include <Qsci/qsciglobal.h>
#include "gui/input/InputDriverManager.h"
#endif

#ifdef ENABLE_CGAL
#include "geometry/cgal/cgal.h"
#include <CGAL/version.h>
#include <boost/algorithm/string.hpp>
#include "geometry/cgal/cgal.h"
#if defined(__GNUG__)
#define GCC_INT_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
#if GCC_INT_VERSION > 40600 || defined(__clang__)
Expand Down Expand Up @@ -48,6 +47,9 @@
#define OPENCSG_VERSION_STRING "<not enabled>"
#endif

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#ifdef ENABLE_MANIFOLD
#include <manifold/version.h> // if it is new enough for us, it has version.h
#define MANIFOLD_VERSION_STRING \
Expand All @@ -58,55 +60,57 @@
#define MANIFOLD_VERSION_STRING "<not enabled>"
#endif

#include "platform/PlatformUtils.h"
#include "version.h"
#include "Feature.h"
#include "FontCache.h"

extern std::vector<std::string> librarypath;
extern std::vector<std::string> fontpath;
extern const std::string get_cairo_version();
extern const std::string get_lib3mf_version();
extern const std::string get_fontconfig_version();
extern const std::string get_harfbuzz_version();
extern const std::string get_freetype_version();
extern const char *LODEPNG_VERSION_STRING;

std::string LibraryInfo::info()
{
std::ostringstream s;

#if defined(__x86_64__) || defined(_M_X64)
std::string bits(" 64bit");
const std::string bits(" 64bit");
#elif defined(__i386) || defined(_M_IX86)
std::string bits(" 32bit");
const std::string bits(" 32bit");
#else
std::string bits("");
const std::string bits("");
#endif

#if defined(__GNUG__) && !defined(__clang__)
std::string compiler_info("GCC " + std::string(TOSTRING(__VERSION__)) + bits);
const std::string compiler_info("GCC " + std::string(TOSTRING(__VERSION__)) + bits);
#elif defined(_MSC_VER)
std::string compiler_info("MSVC " + std::string(TOSTRING(_MSC_FULL_VER)) + bits);
const std::string compiler_info("MSVC " + std::string(TOSTRING(_MSC_FULL_VER)) + bits);
#elif defined(__clang__)
std::string compiler_info("Clang " + std::string(TOSTRING(__clang_version__)) + bits);
const std::string compiler_info("Clang " + std::string(TOSTRING(__clang_version__)) + bits);
#else
std::string compiler_info("unknown compiler");
const std::string compiler_info("unknown compiler");
#endif

#if defined(__MINGW64__)
std::string mingwstatus("MingW64");
const std::string mingwstatus("MingW64");
#elif defined(__MINGW32__)
std::string mingwstatus("MingW32");
const std::string mingwstatus("MingW32");
#else
std::string mingwstatus("No");
const std::string mingwstatus("No");
#endif

#ifdef DEBUG
std::string debugstatus("Yes");
const std::string debugstatus("Yes");
#else
std::string debugstatus("No");
const std::string debugstatus("No");
#endif

#ifdef QT_VERSION
std::string qtVersion = qVersion();
const std::string qtVersion = qVersion();
#else
std::string qtVersion = "Qt disabled - Commandline Test Version";
const std::string qtVersion = "Qt disabled - Commandline Test Version";
#endif

#ifdef ENABLE_CGAL
Expand Down
Loading

0 comments on commit ce6161c

Please sign in to comment.