How to enable c++17 in uproject, VS requires compiler flag /std:c++17

vs2017 compile error:
"error C2429: language feature ‘structured bindings’ requires compiler flag ‘/std:c++17’ "

I know how to enable c++17 in VS2017,but UE project use NMake, there is no way to enable it, how do I do ?

I was modified “VCToolChain.cs” in UnrealBuildTool folder, modify function “AppendCLArguments_Global” and “AppendCLArguments_CPP”, change Arguments.Add("-std=c++14") to Arguments.Add("-std=c++17") and Arguments.Add("/Qstd=c++14") to Arguments.Add("/Qstd=c++17") and re create .sln, but it still doesn’t work !

Hello !

I compiled successfully with the flag std:c++17 with visual studio 2017 :

I checked your modifications and it seems you have changed the flag for the wrong compilers.

You have to add the flag in the file VCToolChain.cs line 632 inside the condition if (!WindowsPlatform.bCompileWithClang) like this :

if (!WindowsPlatform.bCompileWithICL)
{
    Arguments.Add("/std:c++17");
    Arguments.Add("/EHsc");
}

The argument EHsc is for activating management of exceptions, without it it doesn’t compile.

Thank you for answer me, but my VCToolChain.cs not the same as you, I’m using UE 4.20.1, I tried to modify as you say and some other way, but there ware all still not work, can you send your VCToolChain.cs file to my email box bowdar@163.com thank you again

Okay for clarifications here is the beginning of my function AppendCLArguments_CPP

static void AppendCLArguments_CPP(CppCompileEnvironment CompileEnvironment, List<string> Arguments)
{
if (!WindowsPlatform.bCompileWithClang)
{
	// Explicitly compile the file as C++.
	Arguments.Add("/TP");
	//START OF MODIFICATIONS
	if (!WindowsPlatform.bCompileWithICL)
	{
		Arguments.Add("/std:c++17");
		Arguments.Add("/EHsc");
	}
	//END OF MODIFICATIONS
}

I sent you the file by mail by the way.

sorry for the necro, but i can’t get it to work. i’ve mad the changes you’ve listed, but to no avail. is there anything else i must do after making the changes?

Me too. I haven’t been successful so far

Did you check in a .cpp.obj.response file if the argument was in the list ? You probably have to recompile everything after… But maybe check that the argument is there before finishing the full compilation to not waste time.

I had no idea to do so. I have very limited knowledge on how UBT works. I’ll have a look when I’m home. thanks for the tip. do you have any recommended reading for info like that on UBT?

I see it isn’t there in the .response file what should I do?

Have you fixed your issue and if so can you post the results?

Edit:
To configure it working i just did what you said but bCompileWithICL wasn’t found so i just removed that and added this code: Arguments.Add("/std:c++17");

in AppendCLArguments_Global which is in ‪Engine\Source\Programs\UnrealBuildTool\Platform\Windows\VCToolChain.cs

and built the project at \Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.csproj

I think you can add this line at beginning of any of these functions:
AppendCLArguments_Global ( i did this here at line 138)

AppendCLArguments_CPP (line 490/491)

or
AppendLinkArguments (line 634)

Hope this helps