# SE-0196 — Compiler Diagnostic Directives

**URL:** <https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734>\
**Category:** Proposal Reviews\
**Created:** [January 24, 2018, 7:40am UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734 "2018-01-24T07:40:39Z")\
**Posts on this page:** 7\
**Page:** 3

<div class="post-metadata">

**Author:** ![jarod](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jarod/32/364_2.png) [@jarod](https://forums.swift.org/u/jarod)\
**Post date:** [January 25, 2018, 8:33pm UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/41 "2018-01-25T20:33:55Z")

</div>

> What is your evaluation of the proposal?

+1, I've always wanted a `#warning` directive in Swift.

> Is the problem being addressed significant enough to warrant a change to Swift?

Yes. There are workarounds, but imo they're cumbersome enough to make this feature important.

The workaround I've used is to define a global `TODO` symbol that's flagged as deprecated, so you can reference that symbol to produce a warning. However, this can only be used on lines where a standalone expression is supported, i.e. inside a function body, which is quite limiting. Also, the deprecation warning is semantically incorrect as mentioned above, and you can't specify a message at the call site. `#warning` doesn't have any of these limitations.

The other workaround I know of is to use a build script to surface TODO comments as warnings, but it's cumbersome to set this up in every project, and it feels like a hack. Having something standardized and built-in would be very helpful.

> Does this proposal fit well with the feel and direction of Swift?

I think it does.

> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

It's basically the same as `#warning` / `#error` in ObjC, which worked well imo.

> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Read the full proposal and skimmed the discussion.

---

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [January 26, 2018, 1:08am UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/42 "2018-01-26T01:08:10Z")

</div>

Did you consider a #assert, which would be an equivalent of C++'s static\_assert? That could also tip the balance towards explicit parenthesis.

---

<div class="post-metadata">

**Author:** ![harlanhaskins](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/harlanhaskins/32/333_2.png) [@harlanhaskins](https://forums.swift.org/u/harlanhaskins)\
**Post date:** [January 26, 2018, 1:10am UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/43 "2018-01-26T01:10:36Z")

</div>

That could be cool for mutually exclusive build configurations, but if we added `#assert`, I’d want `constexpr` 😈

---

<div class="post-metadata">

**Author:** ![David\_Moore](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/david_moore/32/7639_2.png) [@David\_Moore](https://forums.swift.org/u/David_Moore)\
**Post date:** [January 26, 2018, 2:27am UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/44 "2018-01-26T02:27:28Z")

</div>

## What is your evaluation of the proposal?

Adding these directives to the Swift compiler will be an excellent addition that has a number of particularly handy use cases. Definitely +1 on this.

## Is the problem being addressed significant enough to warrant a change to Swift?

Although this might not be a necessarily essential feature, it's definitely a helpful one that'll hopefully improve code readability and review.

## Does this proposal fit well with the feel and direction of Swift?

Since this is a compiler directive there isn't necessarily a Swifty feel to it, but that is to be expected with such a feature. However, that being said, it _does_ fit in well with the feel and direction of existing Swift compiler directives.

## If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

This is very similar to `#pragma` when using Clang (i.e., Objective-C, C++, etc...), so it should be intuitive for developers coming from those languages. It also improves on that syntax by using appropriate language that explicitly describes the purpose of the directive.

## How much effort did you put into your review?

I read the entire proposal, in addition to the evolution discussion, and was very excited as this is something that I've felt Swift was missing.

---

<div class="post-metadata">

**Author:** ![Nathan\_Gray](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nathan_gray/32/1598_2.png) [@Nathan\_Gray](https://forums.swift.org/u/Nathan_Gray)\
**Post date:** [January 26, 2018, 8:03pm UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/45 "2018-01-26T20:03:32Z")

</div>

+1

This is a small but significant improvement that will be useful in a variety of contexts. The proposed syntax seems fine to me.

---

<div class="post-metadata">

**Author:** ![pkirvan](https://avatars.discourse-cdn.com/v4/letter/p/8c91f0/32.png) [@pkirvan](https://forums.swift.org/u/pkirvan)\
**Post date:** [January 28, 2018, 8:42am UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/46 "2018-01-28T08:42:41Z")

</div>

> [@Nevin](#):
>
> Technically, you can already do that, since “#error” does indeed produce a compiler error. :-)

Oh we know. In Swift as it currently exists you can make an error just by typing ljkhhkljahlkh on the line you want the error to be. Sometimes out of desperation I do just that. However, that doesn't cover the usage case of wanting a warning, not an error, so that I can compile and test other things in the mean time. This proposal also offers a much more professional looking way to get the error. 😀

---

<div class="post-metadata">

**Author:** ![tkremenek](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tkremenek/32/9115_2.png) [@tkremenek](https://forums.swift.org/u/tkremenek)\
**Post date:** [February 2, 2018, 12:27am UTC](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/47 "2018-02-02T00:27:13Z")

</div>

## Review accepted with slight revision

On February 1, 2018 the Core Team decided to **accept** this proposal with slight revision over the [original proposal](https://github.com/apple/swiftevolution/blob/ab0c22a2340be9bfcb82e6f237752b4d959a93b7/proposals/0196-diagnostic-directives.md).

The only revision over the original proposal is to change the syntax to use `#warning(<Message>)` instead of `#warning <Messsage>`. This fits well with most of Swift's existing compiler directives, and was strongly supported in the review discussion.

The review discussion also covered a variety of possible extensions or variants to this proposal, including support for using `#warning` [as an expression](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/21) instead of a line directive and [support for runtime issues](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734/6). The Core Team decided that while these directions are interesting and worth exploring, they are complementary to the core functionality serviced by this proposal. Further, keeping `#warning` as a line directive allows it to be used in a wide variety of contexts, and serves a different need than using it as a placeholder expression.

[Previous page](https://forums.swift.org/t/se-0196-compiler-diagnostic-directives/8734.md?page=2)
