Skip to content

Commit

Permalink
Some MSVC compiler bug has been fixed, remove workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Mar 1, 2024
1 parent b65292a commit 5f2b2a1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 23 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
fail-fast: false
matrix:
language: ["cpp"]
compiler: [g++-11]
buildmode: [Debug]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
Expand All @@ -54,14 +53,14 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libcurl4-gnutls-dev ninja-build ${{matrix.compiler}} --no-install-recommends
sudo apt install build-essential ninja-build libssl-dev libcurl4-gnutls-dev cmake git ca-certificates gzip -y --no-install-recommends
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build

- name: Configure CMake
working-directory: ${{github.workspace}}/build
run: cmake -DCMAKE_BUILD_TYPE=${{matrix.buildmode}} -DCMAKE_CXX_COMPILER=${{matrix.compiler}} -GNinja ..
run: cmake -DCMAKE_BUILD_TYPE=${{matrix.buildmode}} -GNinja ..

- name: Build
working-directory: ${{github.workspace}}/build
Expand All @@ -75,4 +74,4 @@ jobs:
# uses a compiled language

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM ubuntu:22.04 AS build
# Install base & build dependencies, needed certificates for curl to work with https
RUN apt update && \
apt upgrade -y && \
apt install build-essential ninja-build libcurl4-gnutls-dev libssl-dev cmake git ca-certificates gzip -y --no-install-recommends
apt install build-essential ninja-build libssl-dev libcurl4-gnutls-dev cmake git ca-certificates gzip -y --no-install-recommends

# Copy source files
WORKDIR /app/src
Expand Down
10 changes: 1 addition & 9 deletions src/tech/include/cct_exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class exception : public std::exception {
public:
static constexpr int kMsgMaxLen = 80;

template <unsigned N, std::enable_if_t<N <= kMsgMaxLen + 1, bool> = true>
template <int N, std::enable_if_t<N <= kMsgMaxLen + 1, bool> = true>
explicit exception(const char (&str)[N]) noexcept {
// Hint: default constructor constructs a variant holding the value-initialized value of the first alternative
// (index() is zero). In our case, it's a std::array, which is what we want here.
Expand All @@ -34,18 +34,10 @@ class exception : public std::exception {

explicit exception(string&& str) noexcept(std::is_nothrow_move_constructible_v<string>) : _data(std::move(str)) {}

#ifdef CCT_MSVC
// MSVC bug: https://developercommunity.visualstudio.com/t/using-fmtlib-on-a-custom-exceptions-constructor-pa/1673659
// do not use fmt for building an exception waiting for the bug to be fixed...
// Exception message will be incorrect.
template <typename... Args>
explicit exception(std::string_view fmt, Args&&...) : _data(std::in_place_type<string>, fmt) {}
#else
template <typename... Args>
explicit exception(format_string<Args...> fmt, Args&&... args) : _data(std::in_place_type<string>) {
cct::format_to(std::back_inserter(std::get<1>(_data)), fmt, std::forward<Args>(args)...);
}
#endif

const char* what() const noexcept override {
switch (_data.index()) {
Expand Down
9 changes: 0 additions & 9 deletions src/tech/include/cct_invalid_argument_exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <utility>

#include "cct_config.hpp"
#include "cct_exception.hpp"
#include "cct_format.hpp"
#include "cct_string.hpp"
Expand All @@ -15,15 +14,7 @@ class invalid_argument : public exception {

explicit invalid_argument(string&& str) noexcept : exception(std::move(str)) {}

#ifdef CCT_MSVC
// MSVC bug: https://developercommunity.visualstudio.com/t/using-fmtlib-on-a-custom-exceptions-constructor-pa/1673659
// do not use fmt for building an exception waiting for the bug to be fixed...
// Exception message will be incorrect.
template <typename... Args>
explicit invalid_argument(std::string_view fmt, Args&&... args) : exception(fmt, std::forward<Args>(args)...) {}
#else
template <typename... Args>
explicit invalid_argument(format_string<Args...> fmt, Args&&... args) : exception(fmt, std::forward<Args>(args)...) {}
#endif
};
} // namespace cct

0 comments on commit 5f2b2a1

Please sign in to comment.