diff options
author | Phil Christensen <philc@microsoft.com> | 2016-12-01 03:53:23 -0800 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2016-12-01 12:53:23 +0100 |
commit | 20275aa647c5733bc5b1929cba3fd1094c67fb1d (patch) | |
tree | 83175127d46a1eaf0071747a92876f3b3e43a6fa /src/ToolBox | |
parent | 3f4680c80dc510a96efa322054145a807480bab7 (diff) | |
download | coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.tar.gz coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.tar.bz2 coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.zip |
fix permissive C++ code (MSVC /permissive-) (#8337)
* fix permissive C++ code (MSVC /permissive-)
These were found by the C++ compiler group when doing "Real world code"
build tests using /permissive-. We are sharing these with you to help you clean up
your code before the new version of the compiler comes out. For more information on /permissive-
see https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/.
----------------------------
Under /permissive-, skipping the initialization of a variable is not allowed.
As an extension the compiler allowed this when there was no destructor for the type.
void func(bool b)
{
if(b) goto END;
int value = 0; //error C2362: initialization of 'value' is skipped by 'goto END'
int array[10]; //Okay, not initialized.
//... value used here
END:
return;
}
Fix 1) Limit the scope of value:
{
int value = 0;
//... value used here
}
END:
Fix 2) Initialize/declare value before the 'goto'
int value = 0;
if(b) goto END;
//... value used here
END:
Fix 3) Don't initialize value in the variable declaration.
int value;
value = 0
//... value used here
END:
-------------------
Alternative token representations.
The following are reserved as alternative representations for operators:
and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq
//Can't use reserved names for variables:
static int and = 0; // Change name (possibly to 'and_')
void func()
{
_asm {
xor edx,edx // xor is reserved, change to uppercase XOR
or eax,eax // or is reserved, change to uppercase OR
}
}
* Apply formatting patch.
* fixes from code review.
I addressed @janvorli requests from the pull request code review.
Diffstat (limited to 'src/ToolBox')
-rw-r--r-- | src/ToolBox/SOS/Strike/strike.cpp | 6 | ||||
-rw-r--r-- | src/ToolBox/SOS/Strike/util.cpp | 64 |
2 files changed, 37 insertions, 33 deletions
diff --git a/src/ToolBox/SOS/Strike/strike.cpp b/src/ToolBox/SOS/Strike/strike.cpp index 71db902e80..3bb3f50200 100644 --- a/src/ToolBox/SOS/Strike/strike.cpp +++ b/src/ToolBox/SOS/Strike/strike.cpp @@ -4361,8 +4361,10 @@ DECLARE_API(VerifyObj) ExtOut("Unable to build snapshot of the garbage collector state\n"); goto Exit; } - DacpGcHeapDetails *pheapDetails = g_snapshot.GetHeap(taddrObj); - bValid = VerifyObject(*pheapDetails, taddrObj, taddrMT, objSize, TRUE); + { + DacpGcHeapDetails *pheapDetails = g_snapshot.GetHeap(taddrObj); + bValid = VerifyObject(*pheapDetails, taddrObj, taddrMT, objSize, TRUE); + } Exit: if (bValid) diff --git a/src/ToolBox/SOS/Strike/util.cpp b/src/ToolBox/SOS/Strike/util.cpp index 9eec76e42c..b2c96fe219 100644 --- a/src/ToolBox/SOS/Strike/util.cpp +++ b/src/ToolBox/SOS/Strike/util.cpp @@ -254,47 +254,49 @@ HRESULT CreateInstanceCustomImpl( typedef HRESULT (__stdcall IDebugSymbols3::*GetPathFunc)(LPWSTR , ULONG, ULONG*); - // Handle both the image path and the symbol path - GetPathFunc rgGetPathFuncs[] = - { &IDebugSymbols3::GetImagePathWide, &IDebugSymbols3::GetSymbolPathWide }; - - for (int i = 0; i < _countof(rgGetPathFuncs); ++i) { - ULONG pathSize = 0; + // Handle both the image path and the symbol path + GetPathFunc rgGetPathFuncs[] = + { &IDebugSymbols3::GetImagePathWide, &IDebugSymbols3::GetSymbolPathWide }; - // get the path buffer size - if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(NULL, 0, &pathSize) != S_OK) + for (int i = 0; i < _countof(rgGetPathFuncs); ++i) { - continue; - } + ULONG pathSize = 0; - ArrayHolder<WCHAR> imgPath = new WCHAR[pathSize+MAX_LONGPATH+1]; - if (imgPath == NULL) - { - continue; - } + // get the path buffer size + if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(NULL, 0, &pathSize) != S_OK) + { + continue; + } - // actually get the path - if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(imgPath, pathSize, NULL) != S_OK) - { - continue; - } + ArrayHolder<WCHAR> imgPath = new WCHAR[pathSize+MAX_LONGPATH+1]; + if (imgPath == NULL) + { + continue; + } - LPWSTR ctx; - LPCWSTR pathElem = wcstok_s(imgPath, W(";"), &ctx); - while (pathElem != NULL) - { - WCHAR fullName[MAX_LONGPATH]; - wcscpy_s(fullName, _countof(fullName), pathElem); - if (wcscat_s(fullName, W("\\")) == 0 && wcscat_s(fullName, dllName) == 0) + // actually get the path + if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(imgPath, pathSize, NULL) != S_OK) + { + continue; + } + + LPWSTR ctx; + LPCWSTR pathElem = wcstok_s(imgPath, W(";"), &ctx); + while (pathElem != NULL) { - if (SUCCEEDED(CreateInstanceFromPath(clsid, iid, fullName, ppItf))) + WCHAR fullName[MAX_LONGPATH]; + wcscpy_s(fullName, _countof(fullName), pathElem); + if (wcscat_s(fullName, W("\\")) == 0 && wcscat_s(fullName, dllName) == 0) { - return S_OK; + if (SUCCEEDED(CreateInstanceFromPath(clsid, iid, fullName, ppItf))) + { + return S_OK; + } } - } - pathElem = wcstok_s(NULL, W(";"), &ctx); + pathElem = wcstok_s(NULL, W(";"), &ctx); + } } } |