Skip to content

Commit

Permalink
Enable /permissive- and remaining /Zc flags (#11816)
Browse files Browse the repository at this point in the history
This commit enables /permissive- for all projects, as well as all other /Zc
flags not enabled by default by /permissive-. Some projects continue to be
built under /Zc:twoPhase- as JsonUtils.h fails to compile otherwise.

## PR Checklist
* [x] Closes #10703
* [x] I work here
* [x] Tests added/passed
  • Loading branch information
lhecker authored Dec 8, 2021
1 parent 40e3dea commit 2b202ce
Show file tree
Hide file tree
Showing 36 changed files with 268 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
<ClCompile>
<AdditionalIncludeDirectories>..;$(OpenConsoleDir)\dep;$(OpenConsoleDir)\dep\jsoncpp\json;$(OpenConsoleDir)src\inc;$(OpenConsoleDir)src\inc\test;$(WinRT_IncludePath)\..\cppwinrt\winrt;"$(OpenConsoleDir)\src\cascadia\TerminalSettingsModel\Generated Files";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>

<!-- Required for JsonUtils.h. -->
<AdditionalOptions>%(AdditionalOptions) /Zc:twoPhase-</AdditionalOptions>
<!-- Manually disable unreachable code warning, because jconcpp has a ton of that. -->
<DisableSpecificWarnings>4702;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@

<ItemDefinitionGroup>
<ClCompile>
<!-- Disable two-phase name lookup for C++/CLI & C++/CX code. -->
<AdditionalOptions>%(AdditionalOptions) /Zc:twoPhase-</AdditionalOptions>
<DisableSpecificWarnings>4453;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)
;$(IntermediateOutputPath)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(IntermediateOutputPath)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>INLINE_TEST_METHOD_MARKUP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
TRACELOGGING_DECLARE_PROVIDER(g_hTerminalControlProvider);
#include <telemetry/ProjectTelemetry.h>

#include <ShlObj_core.h>
#include <WinUser.h>

#include "til.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
<ClCompile>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..;$(OpenConsoleDir)\dep\jsoncpp\json;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
<!-- Required for JsonUtils.h. -->
<AdditionalOptions>%(AdditionalOptions) /Zc:twoPhase-</AdditionalOptions>
<!-- Manually disable unreachable code warning, because jconcpp has a ton of that. -->
<DisableSpecificWarnings>4702;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/UnitTests_TerminalCore/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class TerminalCoreUnitTests::TestUtils
auto mismatched = (actualChars != expectedChars || actualAttrs != expectedAttrs);
if (mismatched)
{
Log::Comment(NoThrowString().Format(
WEX::Logging::Log::Comment(WEX::Common::NoThrowString().Format(
L"Character or attribute at index %d was mismatched", charsProcessed));
}

Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/ut_app/TerminalApp.UnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
<ClCompile>
<AdditionalIncludeDirectories>..;$(OpenConsoleDir)src\cascadia\inc;$(OpenConsoleDir)\dep\jsoncpp\json;$(OpenConsoleDir)src\inc;$(OpenConsoleDir)src\inc\test;$(WinRT_IncludePath)\..\cppwinrt\winrt;"$(OpenConsoleDir)\src\cascadia\TerminalApp\Generated Files";"$(OpenConsoleDir)\src\cascadia\TerminalSettingsModel\Generated Files";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>

<!-- Required for JsonUtils.h. -->
<AdditionalOptions>%(AdditionalOptions) /Zc:twoPhase-</AdditionalOptions>
<!-- Manually disable unreachable code warning, because jconcpp has a ton of that. -->
<DisableSpecificWarnings>4702;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
Expand Down
4 changes: 3 additions & 1 deletion src/common.build.pre.props
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<ConformanceMode>true</ConformanceMode>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>%(AdditionalOptions) /utf-8 /Zc:externConstexpr /Zc:lambda /Zc:throwingNew</AdditionalOptions>
<ControlFlowGuard>Guard</ControlFlowGuard>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
Expand Down
6 changes: 2 additions & 4 deletions src/cppwinrt.build.pre.props
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>

<!-- All new code should be in non-permissive mode. Big objects for C++/WinRT. -->
<ConformanceMode>true</ConformanceMode>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
<AdditionalOptions>%(AdditionalOptions) /bigobj /Zc:twoPhase-</AdditionalOptions>
<!-- Big objects for C++/WinRT. -->
<AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
<DisableSpecificWarnings>5104;28204;%(DisableSpecificWarnings)</DisableSpecificWarnings>

<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
Expand Down
2 changes: 1 addition & 1 deletion src/host/_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ using Microsoft::Console::VirtualTerminal::StateMachine;
// - STATUS_SUCCESS if OK.
// - CONSOLE_STATUS_WAIT if we couldn't finish now and need to be called back later (see ppWaiter).
// - Or a suitable NTSTATUS format error code for memory/string/math failures.
[[nodiscard]] NTSTATUS DoWriteConsole(_In_reads_bytes_(*pcbBuffer) PWCHAR pwchBuffer,
[[nodiscard]] NTSTATUS DoWriteConsole(_In_reads_bytes_(*pcbBuffer) PCWCHAR pwchBuffer,
_Inout_ size_t* const pcbBuffer,
SCREEN_INFORMATION& screenInfo,
bool requiresVtQuirk,
Expand Down
2 changes: 1 addition & 1 deletion src/host/_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Return Value:

// NOTE: console lock must be held when calling this routine
// String has been translated to unicode at this point.
[[nodiscard]] NTSTATUS DoWriteConsole(_In_reads_bytes_(*pcbBuffer) PWCHAR pwchBuffer,
[[nodiscard]] NTSTATUS DoWriteConsole(_In_reads_bytes_(*pcbBuffer) PCWCHAR pwchBuffer,
_Inout_ size_t* const pcbBuffer,
SCREEN_INFORMATION& screenInfo,
bool requiresVtQuirk,
Expand Down
2 changes: 1 addition & 1 deletion src/host/alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ std::wstring Alias::s_MatchAndCopyAlias(const std::wstring& sourceText,
// - LineCount - aliases can contain multiple commands. $T is the command separator
// Return Value:
// - None. It will just maintain the source as the target if we can't match an alias.
void Alias::s_MatchAndCopyAliasLegacy(_In_reads_bytes_(cbSource) PWCHAR pwchSource,
void Alias::s_MatchAndCopyAliasLegacy(_In_reads_bytes_(cbSource) PCWCH pwchSource,
_In_ size_t cbSource,
_Out_writes_bytes_(cbTargetWritten) PWCHAR pwchTarget,
_In_ const size_t cbTargetSize,
Expand Down
2 changes: 1 addition & 1 deletion src/host/alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Alias
public:
static void s_ClearCmdExeAliases();

static void s_MatchAndCopyAliasLegacy(_In_reads_bytes_(cbSource) PWCHAR pwchSource,
static void s_MatchAndCopyAliasLegacy(_In_reads_bytes_(cbSource) PCWCH pwchSource,
_In_ size_t cbSource,
_Out_writes_bytes_(cbTargetWritten) PWCHAR pwchTarget,
_In_ const size_t cbTargetSize,
Expand Down
2 changes: 1 addition & 1 deletion src/host/ft_host/API_FileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void FileTests::TestUtf8WriteFileInvalid()

DWORD dwWritten;
DWORD dwExpectedWritten;
char* str;
const char* str;
DWORD cbStr;

// \x80 is an invalid UTF-8 continuation
Expand Down
49 changes: 6 additions & 43 deletions src/host/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

// Routine Description:
// - Ensures the SxS initialization for the process.
void InitSideBySide(_Out_writes_(ScratchBufferSize) PWSTR ScratchBuffer, __range(MAX_PATH, MAX_PATH) DWORD ScratchBufferSize)
void InitSideBySide()
{
ACTCTXW actctx = { 0 };

// Account for the fact that sidebyside stuff happens in CreateProcess
// but conhost is run with RtlCreateUserProcess.

Expand All @@ -30,42 +28,11 @@ void InitSideBySide(_Out_writes_(ScratchBufferSize) PWSTR ScratchBuffer, __range
// make references to DLLs in the system that are in the SxS cache (ex. a 3rd party IME is loaded and asks for
// comctl32.dll. The load will fail if SxS wasn't initialized.) This was bug# WIN7:681280.

// We look at the first few chars without being careful about a terminal nul, so init them.
ScratchBuffer[0] = 0;
ScratchBuffer[1] = 0;
ScratchBuffer[2] = 0;
ScratchBuffer[3] = 0;
ScratchBuffer[4] = 0;
ScratchBuffer[5] = 0;
ScratchBuffer[6] = 0;

// GetModuleFileNameW truncates its result to fit in the buffer, so to detect if we fit, we have to do this.
ScratchBuffer[ScratchBufferSize - 2] = 0;
DWORD const dwModuleFileNameLength = GetModuleFileNameW(nullptr, ScratchBuffer, ScratchBufferSize);
if (dwModuleFileNameLength == 0)
{
RIPMSG1(RIP_ERROR, "GetModuleFileNameW failed %d.\n", GetLastError());
goto Exit;
}
if (ScratchBuffer[ScratchBufferSize - 2] != 0)
{
RIPMSG1(RIP_ERROR, "GetModuleFileNameW requires more than ScratchBufferSize(%d) - 1.\n", ScratchBufferSize);
goto Exit;
}

// We get an NT path from the Win32 api. Fix it to be Win32.
UINT NtToWin32PathOffset = 0;
if (ScratchBuffer[0] == '\\' && ScratchBuffer[1] == '?' && ScratchBuffer[2] == '?' && ScratchBuffer[3] == '\\'
//&& ScratchBuffer[4] == a drive letter
&& ScratchBuffer[5] == ':' && ScratchBuffer[6] == '\\')
{
NtToWin32PathOffset = 4;
}

ACTCTXW actctx{};
actctx.cbSize = sizeof(actctx);
actctx.dwFlags = (ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT);
actctx.lpResourceName = MAKEINTRESOURCE(IDR_SYSTEM_MANIFEST);
actctx.lpSource = ScratchBuffer + NtToWin32PathOffset;
// We set ACTCTX_FLAG_HMODULE_VALID, but leave hModule as nullptr.
// A nullptr HMODULE refers to the current process/executable.
actctx.dwFlags = ACTCTX_FLAG_SET_PROCESS_DEFAULT | ACTCTX_FLAG_HMODULE_VALID;

HANDLE const hActCtx = CreateActCtxW(&actctx);

Expand All @@ -83,11 +50,7 @@ void InitSideBySide(_Out_writes_(ScratchBufferSize) PWSTR ScratchBuffer, __range
{
RIPMSG1(RIP_WARNING, "InitSideBySide failed create an activation context. Error: %d\r\n", error);
}
goto Exit;
}

Exit:
ScratchBuffer[0] = 0;
}

// Routine Description:
Expand Down Expand Up @@ -130,5 +93,5 @@ void InitEnvironmentVariables()
}

// Initialize SxS for the process.
InitSideBySide(wchValue, ARRAYSIZE(wchValue));
InitSideBySide();
}
2 changes: 1 addition & 1 deletion src/host/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Tracing::~Tracing()
// Return Value:
// - An object for the caller to hold until the API call is complete.
// Then destroy it to signal that the call is over so the stop trace can be written.
Tracing Tracing::s_TraceApiCall(const NTSTATUS& result, PCSTR traceName)
Tracing Tracing::s_TraceApiCall(const NTSTATUS result, PCSTR traceName)
{
// clang-format off
TraceLoggingWrite(
Expand Down
2 changes: 1 addition & 1 deletion src/host/tracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Tracing
public:
~Tracing();

static Tracing s_TraceApiCall(const NTSTATUS& result, PCSTR traceName);
static Tracing s_TraceApiCall(const NTSTATUS result, PCSTR traceName);

static void s_TraceApi(const NTSTATUS status, const CONSOLE_GETLARGESTWINDOWSIZE_MSG* const a);
static void s_TraceApi(const NTSTATUS status, const CONSOLE_SCREENBUFFERINFO_MSG* const a, const bool fSet);
Expand Down
12 changes: 6 additions & 6 deletions src/host/ut_host/AliasTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class AliasTests

TEST_METHOD(TestMatchAndCopyTrailingCRLF)
{
PWSTR pwszSource = L"SourceWithoutCRLF\r\n";
const auto pwszSource = L"SourceWithoutCRLF\r\n";
const size_t cbSource = wcslen(pwszSource) * sizeof(wchar_t);

const size_t cchTarget = 60;
Expand Down Expand Up @@ -193,7 +193,7 @@ class AliasTests

TEST_METHOD(TestMatchAndCopyInvalidExeName)
{
PWSTR pwszSource = L"Source";
const auto pwszSource = L"Source";
const size_t cbSource = wcslen(pwszSource) * sizeof(wchar_t);

const size_t cchTarget = 12;
Expand Down Expand Up @@ -225,7 +225,7 @@ class AliasTests

TEST_METHOD(TestMatchAndCopyExeNotFound)
{
PWSTR pwszSource = L"Source";
const auto pwszSource = L"Source";
const size_t cbSource = wcslen(pwszSource) * sizeof(wchar_t);

const size_t cchTarget = 12;
Expand Down Expand Up @@ -257,7 +257,7 @@ class AliasTests

TEST_METHOD(TestMatchAndCopyAliasNotFound)
{
PWSTR pwszSource = L"Source";
const auto pwszSource = L"Source";
const size_t cbSource = wcslen(pwszSource) * sizeof(wchar_t);

const size_t cchTarget = 12;
Expand Down Expand Up @@ -294,7 +294,7 @@ class AliasTests

TEST_METHOD(TestMatchAndCopyTargetTooSmall)
{
PWSTR pwszSource = L"Source";
const auto pwszSource = L"Source";
const size_t cbSource = wcslen(pwszSource) * sizeof(wchar_t);

const size_t cchTarget = 12;
Expand Down Expand Up @@ -330,7 +330,7 @@ class AliasTests

TEST_METHOD(TestMatchAndCopyLeadingSpaces)
{
PWSTR pwszSource = L" Source";
const auto pwszSource = L" Source";
const size_t cbSource = wcslen(pwszSource) * sizeof(wchar_t);

const size_t cchTarget = 12;
Expand Down
2 changes: 1 addition & 1 deletion src/host/ut_host/ReadWaitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class InputRecordConversionTests
dbcsChars,
INPUT_RECORD_COUNT * 2,
nullptr,
false);
FALSE);
VERIFY_ARE_EQUAL(writtenBytes, static_cast<int>(INPUT_RECORD_COUNT * 2));
for (size_t i = 0; i < INPUT_RECORD_COUNT * 2; ++i)
{
Expand Down
4 changes: 2 additions & 2 deletions src/host/ut_host/ScreenBufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,7 @@ void ScreenBufferTests::BackspaceDefaultAttrsWriteCharsLegacy()

if (writeSingly)
{
wchar_t* str = L"X";
auto str = L"X";
size_t seqCb = 2;
VERIFY_SUCCESS_NTSTATUS(WriteCharsLegacy(si, str, str, str, &seqCb, nullptr, cursor.GetPosition().X, writeCharsLegacyMode, nullptr));
VERIFY_SUCCESS_NTSTATUS(WriteCharsLegacy(si, str, str, str, &seqCb, nullptr, cursor.GetPosition().X, writeCharsLegacyMode, nullptr));
Expand All @@ -2581,7 +2581,7 @@ void ScreenBufferTests::BackspaceDefaultAttrsWriteCharsLegacy()
}
else
{
wchar_t* str = L"XX\x08";
const auto str = L"XX\x08";
size_t seqCb = 6;
VERIFY_SUCCESS_NTSTATUS(WriteCharsLegacy(si, str, str, str, &seqCb, nullptr, cursor.GetPosition().X, writeCharsLegacyMode, nullptr));
}
Expand Down
Loading

0 comments on commit 2b202ce

Please sign in to comment.