Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Bug Fixes:
- Fix incorrect parsing of environment variables with quoted values containing spaces. [#729](https://github.com/microsoft/vscode-makefile-tools/issues/729)
- Fix build task failure where task definition was missing command property. [#748](https://github.com/microsoft/vscode-makefile-tools/issues/748)
- Added support for C++23 and C++26 standard flags. [#752](https://github.com/microsoft/vscode-makefile-tools/issues/752)
- Add support for C23 and GNU C23 standard flags (`c23`, `gnu23`, `c2x`, `gnu2x`) and fix `iso9899:*` year-based standard flags not being recognized across all C standard branches. [#803](https://github.com/microsoft/vscode-makefile-tools/issues/803)
- Fix path link detection in output panel for non-English locales. [#723](https://github.com/microsoft/vscode-makefile-tools/issues/723)
- Fix script path links not being clickable in localized output for CHS/CHT/DEU/FRA/PLK. [#724](https://github.com/microsoft/vscode-makefile-tools/issues/724)
- Fix file path links not being clickable in output panel for certain locales. [#725](https://github.com/microsoft/vscode-makefile-tools/issues/725)
Expand Down
17 changes: 12 additions & 5 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2244,19 +2244,26 @@ function parseCStandard(
): util.StandardVersion | undefined {
// GNU options from: https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options
const isGnu: boolean = canUseGnu && std.startsWith("gnu");
if (/(c|gnu)(90|89|iso9899:(1990|199409))/.test(std)) {
if (/(c|gnu)(90|89)/.test(std) || /iso9899:(1990|199409)/.test(std)) {
return isGnu ? "gnu89" : "c89";
} else if (/(c|gnu)(99|9x|iso9899:(1999|199x))/.test(std)) {
} else if (/(c|gnu)(99|9x)/.test(std) || /iso9899:(1999|199x)/.test(std)) {
return isGnu ? "gnu99" : "c99";
} else if (/(c|gnu)(11|1x|iso9899:2011)/.test(std)) {
} else if (/(c|gnu)(11|1x)/.test(std) || /iso9899:2011/.test(std)) {
return isGnu ? "gnu11" : "c11";
} else if (/(c|gnu)(17|18|23|2x|iso9899:(2017|2018|2024))/.test(std)) {
} else if (/(c|gnu)(17|18)/.test(std) || /iso9899:(2017|2018)/.test(std)) {
if (canUseGnu) {
// cpptools supports 'c17' in same version it supports GNU std.
// cpptools v4+ supports 'c17'/'gnu17'; older versions fall back to 'c11'.
return isGnu ? "gnu17" : "c17";
} else {
return "c11";
}
} else if (/(c|gnu)(23|2x)/.test(std) || /iso9899:2024/.test(std)) {
if (canUseGnu) {
// cpptools v4+ supports 'c23'/'gnu23'; older versions fall back to 'c11'.
return isGnu ? "gnu23" : "c23";
} else {
return "c11";
}
} else {
return undefined;
}
Expand Down
94 changes: 94 additions & 0 deletions src/test/fakeSuite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,3 +1008,97 @@ suite("Unit testing parseStandard for C++ standards", () => {
);
});
});

suite("Unit testing parseStandard for C standards", () => {
suiteSetup(async function (this: Mocha.Context) {
this.timeout(100000);
});

test("Test C23 standard parsing", () => {
// Test c23 flag
expect(parser.parseStandard(cpp.Version.v6, "c23", "c")).to.be.equal(
"c23"
);
// Test c2x flag (draft name for C23)
expect(parser.parseStandard(cpp.Version.v6, "c2x", "c")).to.be.equal(
"c23"
);
// Test gnu23 flag
expect(parser.parseStandard(cpp.Version.v6, "gnu23", "c")).to.be.equal(
"gnu23"
);
// Test gnu2x flag
expect(parser.parseStandard(cpp.Version.v6, "gnu2x", "c")).to.be.equal(
"gnu23"
);
// Test iso9899:2024 flag
expect(
parser.parseStandard(cpp.Version.v6, "iso9899:2024", "c")
).to.be.equal("c23");
// Test c23 falls back to c11 on cpptools < v4
expect(parser.parseStandard(cpp.Version.v3, "c23", "c")).to.be.equal(
"c11"
);
expect(parser.parseStandard(cpp.Version.v3, "gnu23", "c")).to.be.equal(
"c11"
);
});

test("Test C17 standard parsing", () => {
// Test c17 flag
expect(parser.parseStandard(cpp.Version.v6, "c17", "c")).to.be.equal(
"c17"
);
// Test c18 flag
expect(parser.parseStandard(cpp.Version.v6, "c18", "c")).to.be.equal(
"c17"
);
// Test gnu17 flag
expect(parser.parseStandard(cpp.Version.v6, "gnu17", "c")).to.be.equal(
"gnu17"
);
// Test gnu18 flag
expect(parser.parseStandard(cpp.Version.v6, "gnu18", "c")).to.be.equal(
"gnu17"
);
// Test iso9899:2017 flag
expect(
parser.parseStandard(cpp.Version.v6, "iso9899:2017", "c")
).to.be.equal("c17");
// Test iso9899:2018 flag
expect(
parser.parseStandard(cpp.Version.v6, "iso9899:2018", "c")
).to.be.equal("c17");
});

test("Test older C standard parsing", () => {
// Test c11 flag
expect(parser.parseStandard(cpp.Version.v6, "c11", "c")).to.be.equal(
"c11"
);
// Test iso9899:2011 flag
expect(
parser.parseStandard(cpp.Version.v6, "iso9899:2011", "c")
).to.be.equal("c11");
// Test c99 flag
expect(parser.parseStandard(cpp.Version.v6, "c99", "c")).to.be.equal(
"c99"
);
// Test iso9899:1999 flag
expect(
parser.parseStandard(cpp.Version.v6, "iso9899:1999", "c")
).to.be.equal("c99");
// Test c89 flag
expect(parser.parseStandard(cpp.Version.v6, "c89", "c")).to.be.equal(
"c89"
);
// Test iso9899:1990 flag
expect(
parser.parseStandard(cpp.Version.v6, "iso9899:1990", "c")
).to.be.equal("c89");
// Test iso9899:199409 flag
expect(
parser.parseStandard(cpp.Version.v6, "iso9899:199409", "c")
).to.be.equal("c89");
});
});
2 changes: 2 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type StandardVersion =
| "c99"
| "c11"
| "c17"
| "c23"
| "c++98"
| "c++03"
| "c++11"
Expand All @@ -38,6 +39,7 @@ export type StandardVersion =
| "gnu99"
| "gnu11"
| "gnu17"
| "gnu23"
| "gnu++98"
| "gnu++03"
| "gnu++11"
Expand Down
Loading