4

Context:

/Za, /Ze (Disable Language Extensions):

... the C compiler conforms strictly to the C89/C90 standard

/permissive- (Standards conformance):

... and sets the /Zc compiler options for strict conformance

C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2019:

... /permissive may be specified to turn off strict conformance mode in the compiler.

The second option is meant to disable the strict conformance mode ...

clock:

Note that this is not strictly conformant with ISO C99 ...

Walkthrough: Compile a C program on the command line:

MSVC is compatible with the ANSI C89 and ISO C99 standards, but not strictly conforming.

Question: what is the definition of "strict conformance"? Was it invented by Microsoft?

Note: both C (n2596.pdf) and C++ (n4849.pdf) standards no not use term "strict conformance" / "strictly conforming" applied to the implementation. The implementation is either conforming, either non-conforming. W/o gradations.

UPD. My guess: under "strict conformance" (w.r.t. to implemtation) Microsoft means "conforming implementation w/o support of any extensions".

pmor
  • 5,392
  • 4
  • 17
  • 36
  • 2
    conformance can have varying degrees. strict conformance, or strictly conforming means to conform without any exceptions. You're not going to find this in the standard, that is just how English works. – NathanOliver Oct 14 '21 at 18:06
  • Another issue that permissive- brings to the fore are dependant names in templates. Without permissive- MSVC is very much laxer about requiring "typename"template parameter qualification. – SoronelHaetir Oct 14 '21 at 18:21
  • @NathanOliver The C standard (for example) defines the following terms: "strictly conforming program", "conforming program", "conforming implementation". It does not define "strictly conforming implementation". Hence, what the end user should understand under "strict conformance mode", "strictly conformant with ISO C99", etc.? Maybe Microsoft meant "strict conformance" (applied to the implemtation) == "conforming implementation w/o support of any extensions"? – pmor Oct 14 '21 at 18:22
  • I think this could be considered ambiguous language on MSFT's part. The C standard does define "strictly conforming" as pertains to programs. MSFT probably intends "strict conformance mode" to mean that the compiler requires the program to be strictly conforming, not that the compiler is strictly conforming to the standard (which isn't a thing). – sj95126 Oct 14 '21 at 18:22

2 Answers2

3

A key part of your confusion is that /Za and /Ze are deprecated and haven't been updated in ages. It was introduced for ANSI 98 and hasn't changed since. Don't use those switches, and ignore any references to them in the docs.

The modern Visual C++ "conformance" switch is /permissive- and the various /Zc switches, in combination with /std.

The current "most conformant" options are:

  • C++20 is: /std:c++20
  • C++17 is: /std:c++17 /permissive- /Zc:preprocessor.
  • C++14 is: /std:c++14 /permissive- /Zc:preprocessor.
  • C11 is: /std:c11
  • C17 is: /std:c17

https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/

A bit part of the conformance issues with Visual C++ is related to the preprocessor

https://devblogs.microsoft.com/cppblog/announcing-full-support-for-a-c-c-conformant-preprocessor-in-msvc/

https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/

For the feature-by-feature breakdown, see Microsoft Docs

UPDATE: A few more conformance switches to consider /Zc:__cplusplus /Zc:inline. With VS 2019 16.8 or later, add /Zc:lambda. With VS 2022 17.5 or later, add /Zc:templateScope.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
1

The C11 standard defines a strictly conforming program and implementation in section 4 paragraphs 5-7 as follows:

5 A strictly conforming program shall use only those features of the language and library specified in this International Standard. It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior, and shall not exceed any minimum implementation limit.

6 The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program. A conforming freestanding implementation shall accept any strictly conforming program in which the ∗ use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>. A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.

7 A conforming program is one that is acceptable to a conforming implementation.

While the terms strictly conforming implementation and strict conformance do not appear here, they can be understood to mean an implementation (in a given mode) that will only accept a strictly conforming program (or more accurately, an implementation that doesn't support features not specified in the standard) .

dbush
  • 205,898
  • 23
  • 218
  • 273
  • Accepting all strictly conforming programs and nothing else seems on par with solving the halting problem. I guess they just make a good attempt at weeding out those who don't fit. – Deduplicator Oct 14 '21 at 18:43
  • 1
    @Deduplicator Not really, it's just a matter of not having (or disabling) any language extensions. – dbush Oct 14 '21 at 19:08
  • 1
    Re “an implementation (in a given mode) that will only accept a strictly conforming program”: Deduplicator is right, that is impossible. Determining whether a program produces implementation-defined behavior is equivalent to the Halting Problem. E.g., a program could overflow `int` if and only if it the code that determines whether a program is strictly conforming reports it is strictly conforming when given the program itself. – Eric Postpischil Oct 14 '21 at 19:08
  • 1
    Maybe you could define a strictly conforming implementation to be one that accepts only strictly conforming syntax and grammar, neglecting run-time behavior, although it would not surprise me if problems arise with that too. – Eric Postpischil Oct 14 '21 at 19:10
  • @dbush Useful to [have a look](https://stackoverflow.com/q/67820453/1778275). – pmor Oct 14 '21 at 20:01
  • @EricPostpischil Out of curiosity: what possible problems can arise with "accepts only strictly conforming syntax and grammar"? For example, the grammar is defined formally: [1](https://www.lysator.liu.se/c/ANSI-C-grammar-y.html), [2](https://gist.github.com/codebrainz/2933703#file-c99-y), etc. As well as the [C preprocessing algorithm](https://www.spinellis.gr/blog/20060626/). – pmor Oct 14 '21 at 21:29