Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with the conformant preprocessor, improve validator #4886

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ endif()
set(CMAKE_BUILD_TYPE RelWithDebInfo)

# /utf-8 affects <format>.
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/diagnostics:caret;/W4;/WX;/w14265;/w15038;/w15262;/utf-8>")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/diagnostics:caret;/W4;/WX;/w14265;/w15038;/w15262;/utf-8;/Zc:preprocessor>")

if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark/.git")
message(FATAL_ERROR "google-benchmark is not checked out; make sure to run\n git submodule update --init benchmarks/google-benchmark")
Expand Down
2 changes: 1 addition & 1 deletion stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ add_compile_definitions(_CRTBLD _VCRT_ALLOW_INTERNALS _HAS_OLD_IOSTREAMS_MEMBERS
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "Embedded")

add_compile_options(/WX /Gy
"$<$<COMPILE_LANGUAGE:CXX>:/diagnostics:caret;/W4;/w14265;/w15038;/fastfail;/guard:cf;/Zp8;/std:c++latest;/permissive-;/Zc:threadSafeInit-;/Zl>"
"$<$<COMPILE_LANGUAGE:CXX>:/diagnostics:caret;/W4;/w14265;/w15038;/fastfail;/guard:cf;/Zp8;/std:c++latest;/permissive-;/Zc:preprocessor;/Zc:threadSafeInit-;/Zl>"
"$<$<COMPILE_LANGUAGE:ASM_MASM>:/W3;/nologo;/quiet>"
)

Expand Down
3 changes: 1 addition & 2 deletions tools/validate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ cmake_minimum_required(VERSION 3.29.0)
project(msvc_standard_libraries_validate LANGUAGES CXX)

add_executable(validate-binary validate.cpp)
# we use SAL annotations, so pass /analyze
target_compile_options(validate-binary PRIVATE /W4 /WX /analyze)
target_compile_options(validate-binary PRIVATE /W4 /WX /analyze /Zc:preprocessor)
set_target_properties(validate-binary
PROPERTIES
CXX_STANDARD 23
Expand Down
9 changes: 5 additions & 4 deletions tools/validate/validate.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
Expand All @@ -21,8 +20,10 @@ constexpr size_t max_line_length = 120;

class BinaryFile {
public:
explicit BinaryFile(const filesystem::path& filepath) : m_file(_wfopen(filepath.c_str(), L"rb")) {
if (!m_file) {
explicit BinaryFile(const filesystem::path& filepath) {
const auto err = _wfopen_s(&m_file, filepath.c_str(), L"rb");

if (err != 0 || !m_file) {
println(stderr, "Validation failed: {} couldn't be opened.", filepath.string());
}
}
Expand All @@ -40,7 +41,7 @@ class BinaryFile {
}

~BinaryFile() {
if (fclose(m_file) != 0) {
if (m_file && fclose(m_file) != 0) {
println(stderr, "fclose() failed.");
abort();
}
Expand Down