<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/113511>113511</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang doesn't equate __attribute__((noreturn)) and [[noreturn]]
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          aoates
      </td>
    </tr>
</table>

<pre>
    When `__attribute__((noreturn))` is set on a function pointer, a function marked `[[noreturn]]` cannot be assigned to it.

Original context on gdb-patches mailing list (https://sourceware.org/pipermail/gdb-patches/2024-October/212507.html)

Example:
```
typedef __attribute__((noreturn)) void (*noreturn_ptr)(void);

__attribute__((noreturn)) void function_attr1(void);
[[noreturn]] void function_attr2(void);
void function_noattr(void);

void test(void) {
  noreturn_ptr fptr[3];

  fptr[0] = &function_attr1;   // OK
  fptr[1] = &function_attr2;   // Should be OK?  But is error.
  fptr[2] = &function_noattr;  // Error
}
```

Compiling:

```
$ clang -c -o /dev/null noreturn_test.c
noreturn_test.c:11:11: error: incompatible function pointer types assigning to 'noreturn_ptr' (aka 'void (*)(void) __attribute__((noreturn))') from 'void (*)(void)' [-Wincompatible-function-pointer-types]
   11 |   fptr[1] = &function_attr2;   // Should be OK?  But is error.
      |           ^ ~~~~~~~~~~~~~~~
noreturn_test.c:12:11: error: incompatible function pointer types assigning to 'noreturn_ptr' (aka 'void (*)(void) __attribute__((noreturn))') from 'void (*)(void)' [-Wincompatible-function-pointer-types]
   12 |   fptr[2] = &function_noattr;  // Error
      |           ^ ~~~~~~~~~~~~~~~~
2 errors generated.
```

This seems incorrect --- clang should treat `function_attr2` the same as `function_attr1`.  As a point of reference, GCC does this (it allows the assignment in the second line).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVj2TozgT_jVy0gUlhDF2QDD2DG-wwQTvVW04JaBtdAsSJz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