4

Consider the following:

typedef int;
int main () { return 0; }

If I compile this with clang with no warning specifications I get

warning: typedef requires a name [-Wmissing-declarations]
typedef int;

That's to be expected; typedef int is illegal per section 6.7 of the C11 standard, and per section 5.1.1.3,

A conforming implementation shall produce at least one diagnostic message if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint.

If I compile this using clang -Wno-missing-declarations, it compiles clean, without any diagnostic messages.

My question:
Does this mark clang as a non-conforming implementation, or is it okay to provide the ability to disable what would otherwise be mandatory diagnostics?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
David Hammen
  • 32,454
  • 9
  • 60
  • 108
  • 1
    It seems to me that if anything, clang is conforming just fine and it allows you to specify a flag that makes your use of it non-conforming. – mah Aug 07 '15 at 15:01
  • Related to [Does C standard mandate that platforms must not define behaviors beyond those given in standard](http://stackoverflow.com/q/29830201/1708801) – Shafik Yaghmour Aug 07 '15 at 15:04
  • GCC also allows this however you have to write some other non-conforming code (using implicit int in C99, for example) as quite a few such diagnostics don't have a name/option in GCC. – cremno Aug 07 '15 at 15:28
  • You could say that `clang -Wno-missing-declarations` is for all intents and purposes a different compiler than `clang`. Same for `gcc -ansi -pedantic` vs `gcc`. – ninjalj Aug 07 '15 at 19:25

1 Answers1

3

From the draft C11 standard section 4 Conformance we see that it is not strictly conforming:

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

but it is a conforming implementation since a conforming implementation is allowed to have extensions as long as they don't break a strictly conforming program:

[...]A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.4)

The C-FAQ says:

[...]There are very few realistic, useful, strictly conforming programs. On the other hand, a merely conforming program can make use of any compiler-specific extension it wants to.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • This makes sense. In a similar vein, I see that gcc has the option `-Wno-endif-labels` (clang: `-Wno-extra-tokens`) that bypasses the diagnostic on constructs such as `#endif foo`. Strictly speaking, those labels are illegal. On the other hand, there's lots of legacy code that is loaded with them. Caveat compiler user when it comes to disabling compiler warnings. – David Hammen Aug 07 '15 at 15:39