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

SLVS-1435 Support C Language standard flags #5665

Merged
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
28 changes: 28 additions & 0 deletions src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ public void ConvertCppStandard(string input, string output)
}
}

[TestMethod]
[DataRow("", "")]
[DataRow("Default", "")]
[DataRow(null, "")]
[DataRow("stdclatest", "/std:clatest")]
[DataRow("stdc23", "/std:c23")]
[DataRow("stdc17", "/std:c17")]
[DataRow("stdc11", "/std:c11")]
[DataRow("Invalid", "Unsupported LanguageStandard_C: Invalid")]
public void ConvertCStandard(string input, string output)
{
if ("Invalid".Equals(input))
{
Action action = () => CmdBuilder.ConvertCStandard(input);
action.Should().ThrowExactly<ArgumentException>().And.Message.Should()
.StartWith(output);
}
else
{
CmdBuilder.ConvertCStandard(input).Should().Be(output);
}
}

[TestMethod]
[DataRow("", "")]
[DataRow("Default", "")]
Expand Down Expand Up @@ -237,6 +260,11 @@ public void ConvertStructMemberAlignment(string input, string output)
[DataRow("LanguageStandard", "stdcpp17", "/std:c++17 ")]
[DataRow("LanguageStandard", "stdcpp14", "/std:c++14 ")]
[DataRow("LanguageStandard", "Default", "")]
[DataRow("LanguageStandard_C", "stdclatest", "/std:clatest ")]
[DataRow("LanguageStandard_C", "stdc23", "/std:c23 ")]
[DataRow("LanguageStandard_C", "stdc17", "/std:c17 ")]
[DataRow("LanguageStandard_C", "stdc11", "/std:c11 ")]
[DataRow("LanguageStandard_C", "Default", "")]
[DataRow("ExceptionHandling", "Sync", "/EHsc ")]
[DataRow("ExceptionHandling", "SyncCThrow", "/EHs ")]
[DataRow("ExceptionHandling", "Async", "/EHa ")]
Expand Down
25 changes: 25 additions & 0 deletions src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ internal void AddOptFromProperties(IVCRulePropertyStorage properties)
var cppStandard = GetPotentiallyUnsupportedPropertyValue(properties, "LanguageStandard", "");
AddCmdOpt(ConvertCppStandard(cppStandard));

var cStandard = GetPotentiallyUnsupportedPropertyValue(properties, "LanguageStandard_C", "");
AddCmdOpt(ConvertCStandard(cStandard));

var exceptionHandling = properties.GetEvaluatedPropertyValue("ExceptionHandling");
AddCmdOpt(ConvertExceptionHandling(exceptionHandling));

Expand Down Expand Up @@ -378,6 +381,28 @@ private void AddTrueFalse(IVCRulePropertyStorage ivcRulePropertyStorage, string
return "/std:c++14";
}
}

internal /* for testing */ static string ConvertCStandard(string value)
{
switch (value)
{
default:
throw new ArgumentException($"Unsupported LanguageStandard_C: {value}", nameof(value));
case null:
case "":
case "Default":
return "";
case "stdclatest":
return "/std:clatest";
case "stdc23":
return "/std:c23";
case "stdc17":
return "/std:c17";
case "stdc11":
return "/std:c11";
}
}

/// <summary>
/// Returns the value of a property that might not be supported by the current version of the compiler.
/// If the property is not supported the default value is returned.
Expand Down