Skip to content

Commit b07df43

Browse files
authored
Cleanup standard args handling (#4482)
* Update for c++26 args. * Fix some checks. * Fix == to === * Update to 7.0.2. * Update to 7.0.3. * Fix lint. * Fix lint (2nd try). * Remove changes. * Revert unnecessary changes. * Fix version numbers. * Fix. * Update vscode-cpptools version. * Remove c2y and switch 2023 to 2024. * Remove c++23preview references.
1 parent 648dd12 commit b07df43

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3869,7 +3869,7 @@
38693869
"rimraf": "^3.0.2",
38703870
"string.prototype.matchall": "^4.0.10",
38713871
"tmp": "^0.2.1",
3872-
"vscode-cpptools": "^6.1.0",
3872+
"vscode-cpptools": "^7.1.1",
38733873
"@vscode/extension-telemetry": "^0.9.6",
38743874
"vscode-nls": "^5.0.0",
38753875
"vscode-tas-client": "^0.1.45",

src/cpptools.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle();
2222
const log = createLogger('cpptools');
2323

2424
type Architecture = 'x86' | 'x64' | 'arm' | 'arm64' | undefined;
25-
type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++11" | "c++14" | "c++17" | "c++20" | "c++23" | "gnu89" | "gnu99" | "gnu11" | "gnu17" | "gnu++98" | "gnu++03" | "gnu++11" | "gnu++14" | "gnu++17" | "gnu++20" | "gnu++23" | undefined;
25+
type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++11" | "c++14" | "c++17" | "c++20" | "gnu89" | "gnu99" | "gnu11" | "gnu17" | "gnu++98" | "gnu++03" | "gnu++11" | "gnu++14" | "gnu++17" | "gnu++20" | undefined;
2626
type IntelliSenseMode = "linux-clang-x86" | "linux-clang-x64" | "linux-clang-arm" | "linux-clang-arm64" | "linux-gcc-x86" | "linux-gcc-x64" | "linux-gcc-arm" | "linux-gcc-arm64" | "macos-clang-x86" | "macos-clang-x64" | "macos-clang-arm" | "macos-clang-arm64" | "macos-gcc-x86" | "macos-gcc-x64" | "macos-gcc-arm" | "macos-gcc-arm64" | "windows-clang-x86" | "windows-clang-x64" | "windows-clang-arm" | "windows-clang-arm64" | "windows-gcc-x86" | "windows-gcc-x64" | "windows-gcc-arm" | "windows-gcc-arm64" | "windows-msvc-x86" | "windows-msvc-x64" | "windows-msvc-arm" | "windows-msvc-arm64" | "msvc-x86" | "msvc-x64" | "msvc-arm" | "msvc-arm64" | "gcc-x86" | "gcc-x64" | "gcc-arm" | "gcc-arm64" | "clang-x86" | "clang-x64" | "clang-arm" | "clang-arm64" | undefined;
2727

2828
export interface DiagnosticsCpptools {
@@ -64,15 +64,11 @@ interface TargetDefaults {
6464
defines?: string[];
6565
}
6666

67-
function parseCppStandard(std: string, canUseGnu: boolean, canUseCxx23: boolean): StandardVersion {
67+
function parseCppStandard(std: string, canUseGnu: boolean): StandardVersion {
6868
const isGnu = canUseGnu && std.startsWith('gnu');
69-
if (std.endsWith('++23') || std.endsWith('++2b') || std.endsWith('++latest')) {
70-
if (canUseCxx23) {
71-
return isGnu ? 'gnu++23' : 'c++23';
72-
} else {
73-
return isGnu ? 'gnu++20' : 'c++20';
74-
}
75-
} else if (std.endsWith('++20') || std.endsWith('++2a')) {
69+
if (std === 'c++latest' || std.endsWith('++26') || std.endsWith('++2c') ||
70+
std.endsWith('++23') || std.endsWith('++2b') ||
71+
std.endsWith('++20') || std.endsWith('++2a')) {
7672
return isGnu ? 'gnu++20' : 'c++20';
7773
} else if (std.endsWith('++17') || std.endsWith('++1z')) {
7874
return isGnu ? 'gnu++17' : 'c++17';
@@ -98,7 +94,7 @@ function parseCStandard(std: string, canUseGnu: boolean): StandardVersion {
9894
return isGnu ? 'gnu99' : 'c99';
9995
} else if (/(c|gnu)(11|1x|iso9899:2011)/.test(std)) {
10096
return isGnu ? 'gnu11' : 'c11';
101-
} else if (/(c|gnu)(17|18|2x|iso9899:(2017|2018))/.test(std)) {
97+
} else if (/(c|gnu)(17|18|23|2x|iso9899:(2017|2018|2024))/.test(std)) {
10298
if (canUseGnu) {
10399
// cpptools supports 'c17' in same version it supports GNU std.
104100
return isGnu ? 'gnu17' : 'c17';
@@ -155,7 +151,6 @@ function parseTargetArch(target: string): Architecture {
155151
export function parseCompileFlags(cptVersion: cpptools.Version, args: string[], lang?: string): CompileFlagInformation {
156152
const requireStandardTarget = (cptVersion < cpptools.Version.v5);
157153
const canUseGnuStd = (cptVersion >= cpptools.Version.v4);
158-
const canUseCxx23 = (cptVersion >= cpptools.Version.v6);
159154
// No need to parse language standard for CppTools API v6 and above
160155
const extractStdFlag = (cptVersion < cpptools.Version.v6);
161156
const iter = args[Symbol.iterator]();
@@ -206,7 +201,7 @@ export function parseCompileFlags(cptVersion: cpptools.Version, args: string[],
206201
} else if (extractStdFlag && (value.startsWith('-std=') || lower.startsWith('-std:') || lower.startsWith('/std:'))) {
207202
const std = value.substring(5);
208203
if (lang === 'CXX' || lang === 'OBJCXX' || lang === 'CUDA') {
209-
const s = parseCppStandard(std, canUseGnuStd, canUseCxx23);
204+
const s = parseCppStandard(std, canUseGnuStd);
210205
if (!s) {
211206
log.warning(localize('unknown.control.gflag.cpp', 'Unknown C++ standard control flag: {0}', value));
212207
} else {
@@ -220,7 +215,7 @@ export function parseCompileFlags(cptVersion: cpptools.Version, args: string[],
220215
standard = s;
221216
}
222217
} else if (lang === undefined) {
223-
let s = parseCppStandard(std, canUseGnuStd, canUseCxx23);
218+
let s = parseCppStandard(std, canUseGnuStd);
224219
if (!s) {
225220
s = parseCStandard(std, canUseGnuStd);
226221
}

test/unit-tests/cpptools.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ suite('CppTools tests', () => {
3535
expect(info.standard).to.eql('gnu++14');
3636
info = parseCompileFlags(cpptoolsVersion5, []);
3737
expect(info.standard).to.eql(undefined);
38+
info = parseCompileFlags(cpptoolsVersion5, ['/std:c++latest']);
39+
expect(info.standard).to.eql('c++20');
3840

3941
// Verify CppTools API version 4
4042
info = parseCompileFlags(cpptoolsVersion4, ['-DFOO=BAR']);

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7582,10 +7582,10 @@ vscode-cmake-tools@^1.2.0:
75827582
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-cmake-tools/-/vscode-cmake-tools-1.2.0.tgz"
75837583
integrity sha512-79K8i0l+AfPV28XPoCFCL1BgTVRTPrKZ7YY2KCPOJyy18G/CiriXVa1Gic7A2a16xOoIcsbZRRXoNO0BZTGp9w==
75847584

7585-
vscode-cpptools@^6.1.0:
7586-
version "6.1.0"
7587-
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-cpptools/-/vscode-cpptools-6.1.0.tgz"
7588-
integrity sha512-+40xMmzSlvaMwWEDIjhHl9+W1RH9xaEbiFAAgLWgyL1FXxQWBguWRHgS91qBJbuFAB9H4UBuK94iFMs+7BFclA==
7585+
vscode-cpptools@^7.1.1:
7586+
version "7.1.1"
7587+
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-cpptools/-/vscode-cpptools-7.1.1.tgz#adde3b6d627ddae5397224daa3e41952b219126b"
7588+
integrity sha1-rd47bWJ92uU5ciTao+QZUrIZEms=
75897589

75907590
vscode-nls-dev@^3.3.2:
75917591
version "3.3.2"

0 commit comments

Comments
 (0)