#error and #warning: why include "#error/#warning" in the diagnostic?

I received some feedback from some users who wondered why #error/#warning diagnostics include the actual "#error" in the diagnostic, e.g.:

  t.c:1:2: error: #error this is an error

This seems redundant. Is this necessary? Why not just have:

  t.c:1:2: error: this is an error

Is there a reason the '#error' needs to be there?

It marks explicitly diagnostics that come from source code (as opposed
to diagnostics coming from the compiler).

Dmitri

That seems fine for text output, but for other clients (e.g., IDEs) we have diagnostic categories that could provide the same functionality with a much better experience.

True, no ideas how to do that though. Distinguishing between "compile error because the code is wrong" and "compile error because of a #error" is at least reasonably important I think.

-eric

I received some feedback from some users who wondered why #error/#warning diagnostics include the actual "#error" in the diagnostic, e.g.:

t.c:1:2: error: #error this is an error

This seems redundant. Is this necessary?

It marks explicitly diagnostics that come from source code (as opposed
to diagnostics coming from the compiler).

That seems fine for text output, but for other clients (e.g., IDEs) we have diagnostic categories that could provide the same functionality with a much better experience.

True, no ideas how to do that though. Distinguishing between "compile error because the code is wrong" and "compile error because of a #error" is at least reasonably important I think.

But the caret location makes it blindingly obvious that this came from a #error or #warning. We don't need the diagnostic text to remind us a second time.

Yeah, I'd thought of that later. I was thinking again of text for some reason as IDE output :slight_smile:

-eric

Sent from my iPhone

I received some feedback from some users who wondered why #error/#warning diagnostics include the actual “#error” in the diagnostic, e.g.:

t.c:1:2: error: #error this is an error

This seems redundant. Is this necessary?

It marks explicitly diagnostics that come from source code (as opposed
to diagnostics coming from the compiler).

That seems fine for text output, but for other clients (e.g., IDEs) we have diagnostic categories that could provide the same functionality with a much better experience.

True, no ideas how to do that though. Distinguishing between “compile error because the code is wrong” and “compile error because of a #error” is at least reasonably important I think.

But the caret location makes it blindingly obvious that this came from a #error or #warning. We don’t need the diagnostic text to remind us a second time.

Sure, but not everyone has the caret diagnostics turned on. It seems nice to distinguish in the text where the actual text comes from. That said, it just seems nice-to-have, not super important.

Certainly “#error” seems like a pretty lame way to do this. ;] My initial thought would be:

foo.cc:42:13: error: (from source directive) this code requires widget to be defined

or some variant thereof.

Among other nice things is that then the message is the same between #error and #warning, and only the level changes. The downside I see is that it’s more verbose. Some (obvious) alternatives

foo.cc:42:13: error: source directive: …
foo.cc:42:13: error: … [directive]
foo.cc:42:13: error: … [-Wdirective] (do we even have a flag for these?)

Someone else can probably come up with a nicer way to phrase this than I can…

Sent from my iPhone

I received some feedback from some users who wondered why #error/#warning diagnostics include the actual “#error” in the diagnostic, e.g.:

t.c:1:2: error: #error this is an error

This seems redundant. Is this necessary?

It marks explicitly diagnostics that come from source code (as opposed
to diagnostics coming from the compiler).

That seems fine for text output, but for other clients (e.g., IDEs) we have diagnostic categories that could provide the same functionality with a much better experience.

True, no ideas how to do that though. Distinguishing between “compile error because the code is wrong” and “compile error because of a #error” is at least reasonably important I think.

But the caret location makes it blindingly obvious that this came from a #error or #warning. We don’t need the diagnostic text to remind us a second time.

Sure, but not everyone has the caret diagnostics turned on.

They’re not getting the full benefit of Clang’s diagnostics, and they’ll have far bigger problems than deciding whether Clang generated the error the user code generated the error. For example, when we complain that a + b + c + d has a type error in +, they have no clue which + we’re talking about (and that’s by design).

It seems nice to distinguish in the text where the actual text comes from. That said, it just seems nice-to-have, not super important.

Certainly “#error” seems like a pretty lame way to do this. ;] My initial thought would be:

foo.cc:42:13: error: (from source directive) this code requires widget to be defined

or some variant thereof.

Among other nice things is that then the message is the same between #error and #warning, and only the level changes. The downside I see is that it’s more verbose.

That’s a step up from “#error”, but I still find it unnecessary.

Some (obvious) alternatives

foo.cc:42:13: error: source directive: …
foo.cc:42:13: error: … [directive]
foo.cc:42:13: error: … [-Wdirective] (do we even have a flag for these?)

Someone else can probably come up with a nicer way to phrase this than I can…

I’m totally not digging the “-Wdirective”; it’s too subtle.

  • Doug

It seems nice to distinguish in the text where the actual text comes from. That said, it just seems nice-to-have, not super important.

Certainly “#error” seems like a pretty lame way to do this. ;] My initial thought would be:

foo.cc:42:13: error: (from source directive) this code requires widget to be defined

or some variant thereof.

That seems even more verbose, and not any more clearer.

Among other nice things is that then the message is the same between #error and #warning, and only the level changes. The downside I see is that it’s more verbose.

That’s a step up from “#error”, but I still find it unnecessary.

We can always support another command line flag that causes us to omit the ‘#error’ and the ‘#warning’ in the message for clients that don’t want it (which do exist) since they can use diagnostic categories. That may seem like overkill, but we have plenty of driver flags for controlling the behavior of diagnostics. The suggestion of having “from source directive” is just a poor man’s replacement of not having good diagnostic categories on the command line (where they make less sense).

I’m fine with keeping “#error” for the text diagnostics. People are use to them, and the alternatives aren’t necessarily any better. We also don’t have -W flags for errors anyway, so -Wdirective doesn’t work.

We shouldn’t be introducing a flag to control a minor aspect of two related diagnostics.

  • Doug

Why? We have flags for controlling the depth of macro stacks in text diagnostics. How is this any different?

More generally, I can see different clients wanting to control the diagnostic output of the compiler. We can look for a general solution here; e.g., a single flag that can control various diagnostic options.

It seems nice to distinguish in the text where the actual text comes from. That said, it just seems nice-to-have, not super important.

Certainly “#error” seems like a pretty lame way to do this. ;] My initial thought would be:

foo.cc:42:13: error: (from source directive) this code requires widget to be defined

or some variant thereof.

That seems even more verbose, and not any more clearer.

Among other nice things is that then the message is the same between #error and #warning, and only the level changes. The downside I see is that it’s more verbose.

That’s a step up from “#error”, but I still find it unnecessary.

We can always support another command line flag that causes us to omit the ‘#error’ and the ‘#warning’ in the message for clients that don’t want it (which do exist) since they can use diagnostic categories. That may seem like overkill, but we have plenty of driver flags for controlling the behavior of diagnostics. The suggestion of having “from source directive” is just a poor man’s replacement of not having good diagnostic categories on the command line (where they make less sense).

We shouldn’t be introducing a flag to control a minor aspect of two related diagnostics.

  • Doug

Why? We have flags for controlling the depth of macro stacks in text diagnostics. How is this any different?

That is a general flag that affects every diagnostic Clang can emit. It controls a formatting policy.

What you’re proposing is a flag that tweaks the wording of two specific diagnostics. It’s too narrow in scope to warrant a special flag.

More generally, I can see different clients wanting to control the diagnostic output of the compiler. We can look for a general solution here; e.g., a single flag that can control various diagnostic options.

Options that control general policies (color, word-wrapping, macro/template depth, carets, Fix-Its, ranges) all make sense. Options that tweak the wording of specific diagnostics don’t, because it’s not a useful thing for a user to think about (“oh, I would like that diagnostic to have a slightly different wording. let me go modify my build settings…”) and because this solution just doesn’t scale if we start resolving “what’s the best wording?” discussions by adding a flag.

  • Doug

I agree in principle, but this isn’t an academic problem. For clients (e.g., an IDE) that don’t want to include the #error or #warning in the diagnostic, because they have diagnostic categories to show to user, what would you propose as the solution?

My suggestion is to never include the #error or #warning, nor any text to explicitly stating that this diagnostic comes from a #warning or #error. It provides no value to any client that maps the error over to source code (whether it be through the caret diagnostics, range highlighting/jump-to-error in an IDE, or just plan looking at the line number). And I can’t bring myself to care about clients that don’t map the error over to source code, because this particular set of diagnostics is just the tip of the iceberg for those clients who willfully throw out all of the useful information we provide.

  • Doug

FWIW, at outset I was merely in the “nice to have” camp. Doug’s arguments converted me easily to the “never include this extra text” side of things.

FWIW, I completely agree with Doug.

-Chris

As do I. I’ll prepare a patch to make this change.