Skip to content

goto-cl: map /std:c++17, /std:c++20, /std:c++latest and the C standards - #9629

Draft
tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:kiro/msvc-std-versions-standalone
Draft

tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:kiro/msvc-std-versions-standalone

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

goto-cl knew /std:c++14, /std:c++17 and /std:c++latest, all mapped to
C++14 ("we don't have any newer version at the moment"), and
/std:c++11. Any other value, including /std:c++20 (Visual Studio 2019
16.11 and later), only gave a warning and left the C++ standard at
CBMC's default, C++98 on hosts other than Windows, so code using nullptr
or constexpr failed to parse. The C standards /std:c11, /std:c17 and
/std:clatest were not recognised either, so goto-cl could not select
C23.

Map the values that cl 19.51 (Visual Studio 2026 18.6) accepts, checked
on Compiler Explorer (it warns D9002 "ignoring unknown option" for
/std:c89, c99, c23, c++98, c++11, c++23 and c++26):

  • /std:c++14 and /std:c++17 select C++14 and C++17;
  • /std:c++20, /std:c++23preview and /std:c++latest (_MSVC_LANG 202002L,
    202302L and 202400L) select C++17, the newest standard that CBMC's
    configuration knows, with a warning. CBMC's C++ front end implements
    no feature of the later standards either;
  • /std:c11, /std:c17 and /std:clatest (STDC_VERSION 201112L,
    201710L and 202312L) select C11, C17 and C23. Without /std, cl
    compiles Microsoft's legacy C (no STDC_VERSION), for which CBMC
    keeps its default, C11.

Start from Visual Studio's default, C++14, also when /std is given, so
that an unknown value (still with a warning) or a C standard leaves
C++14 in place, and use the last /std option, as cl does (warning
D9025 "overriding '/std:c17' with '/std:clatest'"). /std:c++11 keeps
selecting C++11 for GCC command-line compatibility.

The tests use preprocessed input, so that no cl.exe is needed. The
goto-cl suite runs on Windows only; on Linux, with goto-cl a symbolic
link to goto-cc, the new tests pass, and all but cxx14 and cxx17 fail
without this change.

Co-authored-by: Kiro kiro-agent@users.noreply.github.com

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

tautschnig and others added 2 commits December 1, 2026 14:09
C23 made alignas, alignof, bool, constexpr, false, nullptr and true
keywords, and CBMC's scanner treated them as keywords in C23 in every
mode. Microsoft's cl does not: with /std:clatest, cl 19.51 (Visual
Studio 2026 18.6, checked on Compiler Explorer) compiles

  int bool; int true; int false; int alignas; int alignof;
  int constexpr; int nullptr;

without a diagnostic at /W4, while it treats typeof, typeof_unqual,
thread_local and static_assert as keywords ("int thread_local;" declares
nothing, warning C4091; the others are syntax errors). typeof,
typeof_unqual and thread_local are keywords only with /std:clatest,
static_assert in all modes. In Visual Studio mode with C23 (cbmc
--winx64 --c23, and goto-cl /std:clatest once goto-cl maps that
option), code that cl accepts, such as "typedef int bool;", therefore
failed to parse.

Treat those seven words as identifiers in Visual Studio mode also in
C23. The other C23 keywords are unchanged: typeof and thread_local
match cl, and _BitInt, a reserved identifier, stays a keyword (cl 19.51
rejects both "_BitInt(8) x;" and "int _BitInt;" in C).

regression/cbmc/constants/predefined-constants1 uses false, true, bool
and nullptr as C23 keywords and therefore becomes gcc-only: Windows
runs the cbmc suite in Visual Studio mode.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
goto-cl knew /std:c++14, /std:c++17 and /std:c++latest, all mapped to
C++14 ("we don't have any newer version at the moment"), and
/std:c++11. Any other value, including /std:c++20 (Visual Studio 2019
16.11 and later), only gave a warning and left the C++ standard at
CBMC's default, C++98 on hosts other than Windows, so code using nullptr
or constexpr failed to parse. The C standards /std:c11, /std:c17 and
/std:clatest were not recognised either, so goto-cl could not select
C23.

Map the values that cl 19.51 (Visual Studio 2026 18.6) accepts, checked
on Compiler Explorer (it warns D9002 "ignoring unknown option" for
/std:c89, c99, c23, c++98, c++11, c++23 and c++26):

- /std:c++14 and /std:c++17 select C++14 and C++17;
- /std:c++20, /std:c++23preview and /std:c++latest (_MSVC_LANG 202002L,
  202302L and 202400L) select C++17, the newest standard that CBMC's
  configuration knows, with a warning. CBMC's C++ front end implements
  no feature of the later standards either;
- /std:c11, /std:c17 and /std:clatest (__STDC_VERSION__ 201112L,
  201710L and 202312L) select C11, C17 and C23. Without /std, cl
  compiles Microsoft's legacy C (no __STDC_VERSION__), for which CBMC
  keeps its default, C11.

Start from Visual Studio's default, C++14, also when /std is given, so
that an unknown value (still with a warning) or a C standard leaves
C++14 in place, and use the last /std option, as cl does (warning
D9025 "overriding '/std:c17' with '/std:clatest'"). /std:c++11 keeps
selecting C++11 for GCC command-line compatibility.

The tests use preprocessed input, so that no cl.exe is needed. The
goto-cl suite runs on Windows only; on Linux, with goto-cl a symbolic
link to goto-cc, the new tests pass, and all but cxx14 and cxx17 fail
without this change.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.66667% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.33%. Comparing base (3e1f386) to head (0b3a5ef).
⚠️ Report is 36 commits behind head on develop.

Files with missing lines Patch % Lines
src/goto-cc/ms_cl_mode.cpp 0.00% 21 Missing ⚠️
src/ansi-c/scanner.l 87.50% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9629      +/-   ##
===========================================
+ Coverage    81.29%   81.33%   +0.04%     
===========================================
  Files         1725     1727       +2     
  Lines       191680   191746      +66     
  Branches        73       73              
===========================================
+ Hits        155835   155966     +131     
+ Misses       35845    35780      -65     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant