2

My question (Single line comment continuation) got me wondering about compiler compliance and warning messages, particularly with warnings-as-error feature in many compilers.

From the C++ spec, § 1.4.2.1 states:

If a program contains no violations of the rules in this International Standard, a conforming implementation shall, within its resource limits, accept and correctly execute that program.

If a warning message is issued for code which technically conforms to the standard (as in my linked question), even if I specifically asked for a warning to be issued (again, in my example if I used -Wcomments with gcc), and I use warning-as-errors (-Werror), the program will not compile. I realize that this is rather obtuse, given that I could workaround the issue in several ways. However, given the quote, is this a violation of the standard which is generally permitted, or is somehow otherwise explicitly allowed?

3
  • 3
    You can think of gcc -Werror as not being a conforming implementation if that helps. Think of it as only a developtment and styling assistant (like Clippy) that helps you create a nice-looking program that you can (or could) give to a conforming implementation. Commented May 25, 2015 at 12:51
  • Is there any documentation and/or indication that you're compiling in non-compliance mode, with gcc, or other compilers? Commented May 25, 2015 at 13:40
  • @MuertoExcobito: GCC's diagnostics certainly distinguish between "real" errors and warnings treated as errors. And of course you can tell that warnings are treated as errors because you specified -Werror. I don't use other compilers enough to comment on them. Commented May 25, 2015 at 14:09

1 Answer 1

6

Yes, if you tell the implementation not to conform with the standard (for example, by requesting errors for well-formed code constructs), then its behaviour won't be conforming.

Sign up to request clarification or add additional context in comments.

7 Comments

@Jefffrey well, assume you write code that technically complies with the standard (even if it's not really great with my comments question). It gets compiled on many different compilers with different options, not all of which you have or can test. With a compiler that supposedly conforms to the standard, but fails compilation based on the compiler options, it might be very important.
@MuertoExcobito: I'm don't see why it might be "very important". It just means that, if you're building (conforming) code of dubious provenance, you might have to disable whatever compiler options you use to impose extra restrictions on your own code.
@MuertoExcobito: That's only important to the people who decided they wanted those warnings. It's not your problem. That said, those people might use the warnings to decide that they don't want to buy your library. :-)
@MuertoExcobito: Then whoever is compiling the code might have to disable whatever options they use to enforce non-standard restrictions on their code. If your code, and their compiler (without non-standard options), are conformant, there should be no problem.
@MikeSeymour fair enough, and likely any issues like this are not going to be that difficult to detect/workaround. However, for example with the gcc documentation, I don't see anywhere that says enabling -Werror turns it into a non-conforming compiler. I would have figured that anything that causes deviation with the standard would be well documented.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.