# clang -Wunreachable-code-break and -Wself-assign-field

**URL:** https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181
**Category:** Engineering
**Created:** [August 6, 2018, 3:37pm UTC](https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181 "2018-08-06T15:37:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![seanm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.itk.org/u/seanm)
#### Post date: [August 6, 2018, 3:37pm UTC](https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181/1 "2018-08-06T15:37:52Z")

</div>

Hi all,

Two warnings on my bots I’m not sure what you all prefer to do about:

1. warning: ‘break’ will never be executed [-Wunreachable-code-break]

```auto
    case itk::ImageIOBase::DOUBLE:
      std::cerr << "Hashing is not supporting for float and double images." << std::endl;
      itkGenericExceptionMacro( "Hashing is not supported for images of float or doubles." );
      break; // <- warning here
    case itk::ImageIOBase::UNKNOWNCOMPONENTTYPE:
    default:
      assert( false ); // should never get here unless we forgot a type
      itkGenericExceptionMacro( "Logic error!" );

```

Do you prefer we remove the break, or I disable this warning flag? It’s the only such warning in all of ITK currently, but I concede it’s maybe not the most useful warning ever.

1. warning: assigning field to itself [-Wself-assign-field]

```auto
/** Concept requiring T to have operator =. (BOOST) */
template< typename T >
struct Assignable {
  struct Constraints {
    void constraints()
    {
      a = a; // <- warning here
      const_constraints(a);
    }

```

I’ve often seen “a = a” as a way to silence unused variable warnings, but this doesn’t look like that…

Cheers,

Sean

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [August 6, 2018, 3:46pm UTC](https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181/2 "2018-08-06T15:46:01Z")

</div>

Remove both offenders in a proposed patch?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [August 6, 2018, 3:49pm UTC](https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181/3 "2018-08-06T15:49:58Z")

</div>

I think just removing the `break` is a good idea.

For the constraint, I think it does some meta-programing type stuff and should _not_ be removed.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [August 6, 2018, 4:53pm UTC](https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181/4 "2018-08-06T16:53:49Z")

</div>

I meant remove statement `a=a;`, not the **constraint**.

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.itk.org/u/seanm)
#### Post date: [August 6, 2018, 5:42pm UTC](https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181/5 "2018-08-06T17:42:16Z")

</div>

So the a=a statement isn’t exercising the existence of the operator= ? The comment above says “Concept requiring T to have operator =”, but I don’t really grok the code.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [August 6, 2018, 5:47pm UTC](https://discourse.itk.org/t/clang-wunreachable-code-break-and-wself-assign-field/1181/6 "2018-08-06T17:47:28Z")

</div>

The code is not run. But the address of the function is taken so is must compile. I believe the intent is to ensure the class has operator=.

Now modern has std::is\_assignable which does a similar and has appropriate variants:

> <https://stackoverflow.com/questions/19920213/why-is-stdis-assignable-counter-intuitive>

Many of these constraints could be replaced with the modern type\_traits, and static\_asserts, but that is a different project.
