2

For an ill-formed C++ program like:

foo^@#$bar%$

Is it standard-compliant for compiler to yield compiled binary with diagnostic message, rather than interrupting the compilation as g++/clang++ do?

intro.compliance states that:

If a program contains a violation of any diagnosable rule or an occurrence of a construct described in this Standard as “conditionally-supported” when the implementation does not support that construct, a conforming implementation shall issue at least one diagnostic message.

which does not require compilation error in this case.

Possibly related:

lz96
  • 2,816
  • 2
  • 28
  • 46

1 Answers1

5

Yes, it is legal for the implementation to produce a binary when the input is an ill-formed program. Here is [intro.compliance]/8 in C++14:

A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any well-formed program. Implementations are required to diagnose programs that use such extensions that are ill-formed according to this International Standard. Having done so, however, they can compile and execute such programs.

In such cases the diagnostic would usually be referred to as a "warning" (as opposed to "error").

Brian Bi
  • 111,498
  • 10
  • 176
  • 312