Skip to content

Commit 46d3095

Browse files
authored
Fix errors to comply with VS 2022 (#20)
* Fixes for VS 2022 * Reusable workflows * Update vcpkg baseline
1 parent 9bb111c commit 46d3095

11 files changed

+33
-168
lines changed

.github/workflows/build.yml

+3-89
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build
1+
name: Build
22

33
on:
44
push:
@@ -11,91 +11,5 @@ on:
1111

1212
jobs:
1313
build:
14-
name: Build and Analyze
15-
runs-on: windows-2022
16-
strategy:
17-
matrix:
18-
configuration: [ Debug, Release ]
19-
20-
steps:
21-
- name: Checkout
22-
uses: actions/checkout@v2
23-
24-
- name: Cache vcpkg
25-
uses: actions/cache@v2
26-
with:
27-
path: build/${{matrix.configuration}}/vcpkg_installed
28-
key: vcpkg_installed-${{matrix.configuration}}-${{hashFiles('**/vcpkg.json', '**/vcpkg-configuration.json', '!build/**')}}
29-
30-
- name: Setup MSVC Environment
31-
uses: mbeckh/msvc-dev-cmd@master
32-
33-
- name: Configure
34-
uses: mbeckh/cmake-utils/configure@master
35-
with:
36-
build-root: build
37-
binary-dir: build/${{matrix.configuration}}
38-
configuration: ${{matrix.configuration}}
39-
extra-args: -D CMAKE_UNITY_BUILD:BOOL=ON -D CMAKE_DISABLE_PRECOMPILE_HEADERS:BOOL=ON -D CMU_DISABLE_DEBUG_INFORMATION_RELEASE:BOOL=ON
40-
41-
- name: Build
42-
shell: cmd
43-
working-directory: build/${{matrix.configuration}}
44-
run: cmake --build .
45-
46-
- name: Test
47-
if: matrix.configuration != 'Debug'
48-
shell: cmd
49-
working-directory: build/${{matrix.configuration}}
50-
run: ctest --output-on-failure
51-
52-
- name: Coverage
53-
if: matrix.configuration == 'Debug'
54-
uses: mbeckh/code-quality-actions/coverage@master
55-
with:
56-
binary-dir: build/${{matrix.configuration}}
57-
codacy-token: ${{secrets.CODACY_PROJECT_API_TOKEN}}
58-
59-
- name: Codecov
60-
if: matrix.configuration == 'Debug'
61-
uses: codecov/codecov-action@v2
62-
with:
63-
files: build/${{matrix.configuration}}/coverage-*.xml
64-
fail_ci_if_error: true
65-
66-
- name: Analyze
67-
shell: cmd
68-
working-directory: build/${{matrix.configuration}}
69-
run: cmake --build . --target clang-tidy
70-
71-
- name: Report
72-
uses: mbeckh/code-quality-actions/report@master
73-
with:
74-
mode: partial
75-
binary-dir: build/${{matrix.configuration}}
76-
codacy-token: ${{secrets.CODACY_PROJECT_API_TOKEN}}
77-
78-
- name: Save Logs
79-
if: always()
80-
uses: actions/[email protected]
81-
with:
82-
name: ${{matrix.configuration}}-Logs
83-
path: |
84-
build/**/vcpkg-buildtrees/*/*.log
85-
build/${{matrix.configuration}}/Testing/**/*.log
86-
build/${{matrix.configuration}}/clang-tidy-*.log
87-
88-
final:
89-
name: Send Completion Message
90-
runs-on: windows-latest
91-
needs: build
92-
93-
steps:
94-
- name: Checkout
95-
uses: actions/checkout@v2
96-
97-
- name: Report
98-
uses: mbeckh/code-quality-actions/report@master
99-
with:
100-
mode: final
101-
codacy-token: ${{secrets.CODACY_PROJECT_API_TOKEN}}
14+
uses: mbeckh/cmake-utils/.github/workflows/run-build.yml@v1
15+
secrets: inherit

.github/workflows/codeql-analysis.yml

+4-48
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,9 @@ on:
99
- '**/*.md'
1010
- '**/*.txt'
1111
schedule:
12-
- cron: '21 8 * * 1'
12+
- cron: '21 8 4 * *'
1313

1414
jobs:
15-
analyse:
16-
name: Analyze
17-
runs-on: windows-2019
18-
permissions:
19-
security-events: write
20-
21-
steps:
22-
- name: Checkout repository
23-
uses: actions/checkout@v2
24-
25-
- name: Cache vcpkg
26-
uses: actions/cache@v2
27-
with:
28-
path: build/Release/vcpkg_installed
29-
key: vcpkg_installed-Release-${{hashFiles('**/vcpkg.json', '**/vcpkg-configuration.json', '!build/**')}}
30-
31-
- name: Setup MSVC Environment
32-
uses: mbeckh/msvc-dev-cmd@master
33-
34-
- name: Configure
35-
uses: mbeckh/cmake-utils/configure@master
36-
with:
37-
build-root: build
38-
binary-dir: build/Release
39-
configuration: Release
40-
extra-args: -D CMAKE_UNITY_BUILD:BOOL=ON -D CMAKE_DISABLE_PRECOMPILE_HEADERS:BOOL=ON -D CMU_DISABLE_DEBUG_INFORMATION:BOOL=ON
41-
42-
- name: Initialize CodeQL
43-
if: github.event_name != 'pull_request'
44-
uses: github/codeql-action/init@v1
45-
with:
46-
languages: cpp
47-
queries: security-and-quality
48-
49-
- name: Initialize CodeQL for Pull Request
50-
if: github.event_name == 'pull_request'
51-
uses: github/codeql-action/init@v1
52-
with:
53-
languages: cpp
54-
55-
- name: Build
56-
shell: cmd
57-
working-directory: build/Release
58-
run: cmake --build .
59-
60-
- name: Perform CodeQL Analysis
61-
uses: github/codeql-action/analyze@v1
15+
build:
16+
uses: mbeckh/cmake-utils/.github/workflows/run-codeql.yml@v1
17+
secrets: inherit

NOTICE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
common-cpp
2-
Copyright 2019 Michael Beckh
2+
Copyright 2019-2022 Michael Beckh
33

44
This product includes software developed by
55
Michael Beckh (https://github.com/mbeckh/common-cpp/).

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# common-cpp
2+
A collection of common classes for C++ programming, particularly for targeting Windows API and COM.
23

3-
[![Release](https://img.shields.io/github/v/tag/mbeckh/common-cpp?label=Release&style=flat-square)](https://github.com/mbeckh/common-cpp/releases/)
4-
[![Tests](https://img.shields.io/github/workflow/status/mbeckh/common-cpp/build/master?label=Tests&logo=GitHub&style=flat-square)](https://github.com/mbeckh/common-cpp/actions)
4+
[![Release](https://img.shields.io/github/v/release/mbeckh/common-cpp?display_name=tag&sort=semver&label=Release&style=flat-square)](https://github.com/mbeckh/common-cpp/releases/)
5+
[![Tests](https://img.shields.io/github/workflow/status/mbeckh/common-cpp/Build/master?label=Tests&logo=GitHub&style=flat-square)](https://github.com/mbeckh/common-cpp/actions)
56
[![Coverage](https://img.shields.io/codecov/c/gh/mbeckh/common-cpp/master?label=Coverage&logo=codecov&style=flat-square)](https://codecov.io/gh/mbeckh/common-cpp)
67
[![Codacy Grade](https://img.shields.io/codacy/grade/d1c1975989c642f2817ffc7160ff6f92?label=Code%20Quality&logo=codacy&style=flat-square)](https://www.codacy.com/manual/mbeckh/common-cpp?utm_source=github.com&utm_medium=referral&utm_content=mbeckh/SystemTools&utm_campaign=Badge_Grade)
78
[![License](https://img.shields.io/github/license/mbeckh/common-cpp?label=License&style=flat-square)](https://github.com/mbeckh/common-cpp/blob/master/LICENSE)
89

9-
A collection of common classes for C++ programming, particularly for targeting Windows API and COM.
10+
## License
11+
The code is released under the Apache License Version 2.0. Please see [LICENSE](LICENSE) for details and
12+
[NOTICE](NOTICE) for the required information when using common-cpp in your own work.

include/m3c/LogArgs.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class LogFormatArgs : private internal::LogFormatArgsBase {
336336
AddArgumentFallback(arg);
337337
} else {
338338
// prevent storing references to temporary objects
339-
static_assert_no_clang(false, "MUST NOT use rvalue to add to LogFormatArgs");
339+
static_assert(sizeof(T) == 0, "MUST NOT use rvalue to add to LogFormatArgs");
340340
}
341341
return *this;
342342
}
@@ -356,7 +356,7 @@ class LogFormatArgs : private internal::LogFormatArgsBase {
356356
AddArgumentFallback(arg);
357357
} else {
358358
// prevent storing references to temporary objects
359-
static_assert_no_clang(false, "MUST NOT use rvalue to add to LogFormatArgs");
359+
static_assert(sizeof(T) == 0, "MUST NOT use rvalue to add to LogFormatArgs");
360360
}
361361
return *this;
362362
}
@@ -398,10 +398,10 @@ class LogEventArgs : private internal::LogEventArgsBase {
398398
AddArgument(std::forward<T>(arg));
399399
} else {
400400
if constexpr (std::is_rvalue_reference_v<T&&>) {
401-
static_assert_no_clang(false, "MUST NOT use rvalue to add to LogEventArgs");
401+
static_assert(sizeof(T) == 0, "MUST NOT use rvalue to add to LogEventArgs");
402402
}
403403
// prevent storing references to temporary objects
404-
static_assert_no_clang(false, "MUST use custom operator>> to add to LogEventArgs");
404+
static_assert(sizeof(T) == 0, "MUST use custom operator>> to add to LogEventArgs");
405405
}
406406
return *this;
407407
}

include/m3c/type_traits.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ limitations under the License.
2424
#include <span>
2525
#include <type_traits>
2626

27-
#ifdef __clang_analyzer__
28-
// clang can't handle some static_assert checks in templated code
29-
// NOLINTNEXTLINE(readability-identifier-naming): Kind of funny that clang complains about a macro to work around shortcomings of clang.
30-
#define static_assert_no_clang(...)
31-
#else
32-
#define static_assert_no_clang(...) static_assert(__VA_ARGS__)
33-
#endif
34-
3527
#define M3C_SELECT_STRING(...) __VA_ARGS__, L##__VA_ARGS__
3628

3729
namespace m3c {
@@ -48,7 +40,7 @@ consteval _Ret_z_ const CharT* SelectString(_In_z_ const char* const sz, _In_z_
4840
} else if constexpr (std::is_same_v<wchar_t, CharT>) {
4941
return wsz;
5042
} else {
51-
static_assert_no_clang(false, "Unknown char type");
43+
static_assert(sizeof(CharT) == 0, "Unknown char type");
5244
}
5345
}
5446

src/ComObject.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ULONG Unknown::UnknownImpl::Release() noexcept {
4040
}
4141

4242
AbstractComObject* Unknown::UnknownImpl::GetAbstractComObject() noexcept {
43-
static_assert_no_clang(offsetof(Unknown, m_unknown) == 0);
43+
static_assert(offsetof(Unknown, m_unknown) == 0);
4444
#pragma warning(suppress : 26491) // valid as checked by static_assert
4545
return static_cast<AbstractComObject*>(reinterpret_cast<Unknown*>(this)); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast): Pointer magic :-)
4646
}

src/LogData.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void DecodeArgument(_Inout_ A& args, _In_ const std::byte* __restrict const buff
312312
args << arg;
313313
}
314314
} else {
315-
static_assert_no_clang(false, "Unknown argument type");
315+
static_assert(sizeof(A) == 0, "Unknown argument type");
316316
}
317317

318318
position += kTypeSize<T> + padding;
@@ -341,10 +341,10 @@ void DecodeArgument(_Inout_ A& args, _In_ const std::byte* __restrict const buff
341341
} else if constexpr (std::is_same_v<B, wchar_t>) {
342342
args + EncodeUtf8(str, length);
343343
} else {
344-
static_assert_no_clang(false, "Unknown string type");
344+
static_assert(sizeof(B) == 0, "Unknown string type");
345345
}
346346
} else {
347-
static_assert_no_clang(false, "Unknown argument type");
347+
static_assert(sizeof(A), "Unknown argument type");
348348
}
349349
position += kTypeSize<T> + padding + length * static_cast<Align>(sizeof(B)) + static_cast<Align>(sizeof(B));
350350
}
@@ -369,7 +369,7 @@ void DecodeArgument(_Inout_ A& args, _In_ const std::byte* __restrict const buff
369369
} else if constexpr (std::is_same_v<A, LogFormatArgs>) {
370370
args << arg;
371371
} else {
372-
static_assert_no_clang(false, "Unknown argument type");
372+
static_assert(sizeof(A) == 0, "Unknown argument type");
373373
}
374374

375375
position += kTypeSize<SID> + padding + size;
@@ -394,7 +394,7 @@ void DecodeArgument(_Inout_ A& args, _Inout_ const std::byte* __restrict const b
394394
} else if constexpr (std::is_same_v<A, LogFormatArgs>) {
395395
pFunctionTable->addFormatArgs(args, &buffer[position + kArgSize + padding]);
396396
} else {
397-
static_assert_no_clang(false, "Unknown argument type");
397+
static_assert(sizeof(A) == 0, "Unknown argument type");
398398
}
399399
position += kArgSize + padding + pFunctionTable->size;
400400
}
@@ -783,13 +783,13 @@ LogDataBase::~LogDataBase() noexcept {
783783
// ensure proper memory layout
784784
static_assert(sizeof(LogDataBase) == M3C_LOGDATA_SIZE, "size of LogLine");
785785

786-
static_assert_no_clang(offsetof(LogDataBase, m_stackBuffer) == 0, "offset of m_stackBuffer");
786+
static_assert(offsetof(LogDataBase, m_stackBuffer) == 0, "offset of m_stackBuffer");
787787
#if UINTPTR_MAX == UINT64_MAX
788-
static_assert_no_clang(offsetof(LogDataBase, m_used) == M3C_LOGDATA_SIZE - 4, "offset of m_used");
788+
static_assert(offsetof(LogDataBase, m_used) == M3C_LOGDATA_SIZE - 4, "offset of m_used");
789789
#elif UINTPTR_MAX == UINT32_MAX
790-
static_assert_no_clang(offsetof(LogDataBase, m_used) == M3C_LOGDATA_SIZE - 4, "offset of m_used");
790+
static_assert(offsetof(LogDataBase, m_used) == M3C_LOGDATA_SIZE - 4, "offset of m_used");
791791
#else
792-
static_assert_no_clang(false, "layout assertions not defined");
792+
static_assert(false, "layout assertions not defined");
793793
#endif
794794
if ((!m_hasHeapBuffer || GetHeapBuffer().use_count() == 1) && m_hasNonTriviallyCopyable) {
795795
[[unlikely]];

test/Log.test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Log_Test : public t::Test {
209209
}
210210

211211
template <EVENT_DESCRIPTOR kLoggedExceptionEvent = EVENT_DESCRIPTOR{}, bool kNested = false, bool kHResult = false, typename E = int, typename D = int, typename... Args>
212-
auto TestMethod(const char* const dynamicLogMessage = "", E&& exception = 0, const char* const exceptionMessage = nullptr, const D detail = 0, Args&&... args) {
212+
auto TestMethod(const char* const dynamicLogMessage = "", E&& exception = 0, const char* const exceptionMessage = nullptr, [[maybe_unused]] const D detail = 0, Args&&... args) {
213213
constexpr bool kException = !std::is_same_v<E, int>;
214214
constexpr bool kDetail = !std::is_same_v<D, int>;
215215
const EventType eventType = GetEventType();

test/lazy_string.test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct CharTNames {
9292
} else if constexpr (std::is_same_v<T, wchar_t>) {
9393
return "1_wchar_t";
9494
} else {
95-
static_assert_no_clang(false, "unknown type");
95+
static_assert(sizeof(T) == 0, "unknown type");
9696
}
9797
}
9898
};

vcpkg-configuration.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"default-registry": {
33
"kind": "builtin",
4-
"baseline": "70033dbb31527fb3e69654731f540f59c87787f9"
4+
"baseline": "48cc0c71ed61be1c0e3c9543dd0f2b997037d1c9"
55
},
66
"registries": [
77
{
88
"kind": "git",
99
"repository": "https://github.com/mbeckh/vcpkg-registry.git",
10-
"baseline": "ded1cdfa4453537af1dcf9dda1de2d82e7646fe6",
10+
"baseline": "3968e6edc820dc3d666b3d3383f096b1998eb8e7",
1111
"packages": [ "common-cpp-testing", "detours", "detours-gmock", "fmt", "gtest" ]
1212
}
1313
]

0 commit comments

Comments
 (0)