C++ resumable functions (yield) in visual studio 2015 RC access violation - c++

I'm trying the code example for resumable functions in Visual Studio 2015 RC from this MSDN link.
#include<iostream>
#include<experimental/generator>
auto hello()
{
for (auto ch : "Hello, world\n")
yield ch;
}
int main()
{
for (auto ch : hello())
std::cout << ch;
}
So far, no matter what my compiler settings are, the code causes an access violation exception when run.
Here are my compiler flags:
/Yu"stdafx.h" /GS- /W3 /Zc:wchar_t /ZI /Gm /Od /sdl- /Fd"x64\Debug\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /MDd /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\Test.pch"
Anyone figure out how to get it working?

I got a response from a comment on the original MSDN link. The problem is with the /ZI flag (program database for edit and continue) which is not supported yet. Switching to /Zi works.

Related

Compiler warning for statement on same line as #endif

Consider code:
#include <stdio.h>
int main() {
int a = 4;
#if 1
printf("Hello world\n");
#endif a++;
printf("a is %d\n", a);
}
Inadvertently, statement a++; is on the same line as a #endif and is not evaluated. As a result, the final output is:
Hello world
a is 4
On x86-64 clang 12, this is captured as a warning with using option -Wextra-tokens. See here.
I tried compiling this on Visual Studio 2019 MSVC, with command line options:
/JMC /permissive- /ifcOutput "Debug\" /GS /analyze- /W3 /Zc:wchar_t /I"../include/" /ZI /Gm- /Od /sdl /Fd"Debug\vc142.pdb" /Zc:inline /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /FC /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\windows.pch" /diagnostics:column
There is no warning of any sort on compilation. Is there a setting that can be passed to the compiler in MSVC that detects extra tokens?
Edited to add:
As answered by user Nathan Pierson, it was indeed option /Za that worked. It does not seem to be on by default. I was also unable to use the Visual Studio Project Properties dialog to find out the option to set. Yet, one can feed in extra options manually thus:
There's compiler warning C4067. It looks like you need to set the flag /Za for it to apply to #endif directives.
In the Visual Studio properties page, this flag is controlled by the setting "Disable Language Extensions" in the Language subsection of the C/C++ section.

How to use Standard Library Header Units in MSVC?

According to Microsoft ( https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-160 ), it implemented P1502R1 Standard library header units for C++20:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1502r1.html
in the latest Visual Studio 2019.
So one can write, e.g.:
import <vector>;
But if I do it in my Visual Studio 2019 16.10.3 (with /std:c++latest switch), the following compilation error arises:
error C7612: could not find header unit for 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vector'
The complete command-line in Debug configuration:
/JMC /experimental:module /external:env:"EXTERNAL_INCLUDE" /permissive- /ifcOutput "x64\Debug\" /GS /W4 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"x64\Debug\vc142.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++latest /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\Project1.pch" /diagnostics:column
Please help how to activate this new feature in MSVC?

Build an x64 DLL with Visual Studio

I'm trying to build my dll file as x64, here are the configurations I have done on VisualStudio:
I have set solution and project platform to x64:
According to this answer, I have changed naming convention from __cdecl to __fastcall:
According to this comment I have added the argument _WIN64 to Preprocessor Definitions:
But still, when I rebuild my project and open my dll file using notepad, I see PE L which means my dll file is 32 bit.
Here's the command line options of the C/C++ settings (for better reading, I put a couple of line breaks in there):
/JMC /permissive- /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl
/Fd"x64\Debug\vc142.pdb" /Zc:inline /fp:precise /D "_WIN64" /D "_DEBUG" /D
"_CONSOLE" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX-
/Zc:forScope /RTC1 /Gr /MDd /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\"
/Fp"x64\Debug\DllCall-CppConsoleApp-1.pch" /diagnostics:column
Linker settings:
What should I do?

Why the "Vector Iterators Incompatible" error only occurs in debug mode?

I noticed I get a "Vector Iterators Incompatible" error when I try to compare two different copies of a vector.
There are enough questions about this error to find how to solve it:
Why am I getting “vector iterators incompatible”?
C++ STL vector iterators incompatible
Debug Assertion : Vector iterators incompatible (C++)
Vector Iterators Incompatible
My question is: is it possible to either disable the check in debug or enable the check in release to make both configurations behave the same way?
My question is NOT: What the error means, what causes it, or how to resolve it.
Additional Details
My compiler options, in debug mode, are:
/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\test.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue
And, in release mode:
/Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Release\test.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue
Here is a little snippet of code to reproduce the error:
#include <vector>
#include <iostream>
#include <string>
using namespace std;
class foo{
public:
const std::vector<int> getVec(){return myVec;} //other stuff omitted
private:
std::vector<int> myVec;
};
int main(int argc, char* argv[])
{
foo myFoo = foo();
std::vector<int>::const_iterator i = myFoo.getVec().begin();
while( i != myFoo.getVec().end())
{
//do stuff
++i;
}
string s;
cin >> s;
return 0;
}

How to make 2 Visual Studio C++ settings identical and remove managed targeted code assembling error?

I have 2 very similar projects (concole Visual C++) but in one of them in the Release Mode I am getting the error:
managed targeted code requires a '/clr' option
I am comparing the Properties C/C++ command line:
The error Project:
/Zi /nologo /W3 /WX- /O2 /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_UNICODE" /D "UNICODE" /Gm- /MT /GS- /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Release\airl.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll" /analyze- /errorReport:queue
The No Error (good) Project
/Zi /nologo /W3 /WX- /O2 /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Release\prj.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue
There are a few differences, but I do not know how to remove
/FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll"
What about Gd option in the good configuration?