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

    <tr>
        <th>Summary</th>
        <td>
            attributes not allowed in any order inside extern "C" {} block
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    With clang 18, in C++ mode, attributes at the beginning of a declaration or function definition are not allowed in any order inside an extern "C" {} block.

For comparison, outside of an extern "C" {} block, it's allowed.

See:
=============================== foo.cc =============================
```
extern "C" {

__attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int coox1 (int); // still error in clang 18
[[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int coox2 (int);

__attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int coos1 (int x) { return x; }; // still error in clang 18
[[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) static int coos2 (int x) { return x; };

}

__attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int foox1 (int); // error in clang < 16
[[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int foox2 (int);

__attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int foos1 (int x) { return x; }; // error in clang < 16
[[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) static int foos2 (int x) { return x; };
```
```
$ clang++ -S -Wall foo.cc
foo.cc:3:42: error: an attribute list cannot appear here
    3 | __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int coox1 (int); // still error in clang 18
      | ^~~~~~~~~~~~~~~~~~~~
foo.cc:6:42: error: an attribute list cannot appear here
    6 | __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int coos1 (int x) { return x; }; // still error in clang 18
      | ^~~~~~~~~~~~~~~~~~~~
2 errors generated.
```

For comparison, in C mode, the same attributes are allowed in any order since clang 17. See:
=================================== foo.c ==============================
```
__attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int coox1 (int); // error in clang < 17
[[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int coox2 (int); // error in clang < 17

__attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int coos1 (int x) { return x; }; // error in clang < 17
[[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) static int coos2 (int x) { return x; }; // error in clang < 17
```
```
$ clang -S -Wall foo.c
```
(no warning or error)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV81yozgQfhpx6YoLmv8Dh9hev8Ac5kgJ1La1K0suSUySyz77lsCeJJ4k6-wWzlBUIkBqfV-r3f01d07uNFHD8iXL1xEf_N7Ypttz2SmKOiOemu_S76FXXO8gqRiuQGpYMVwyXMLBCAqvuPdWdoMnB9yD3xN0tJNaS70DswUOgnrFLffSaDAWtoPux7GgrdRyHHJLoI0HrpR5IBG24foJjBVkQWonBQHXQI-erAaGuGKIwMolK9fQKdP_tWDxmsX309-NsdCbw5Fb6YwOIM3gRyMB0Id2RpKeYenOYF5Z_kbE0tOYpev5btgas-h7mGuHiUERn-7x8Q23vKDetj9Pum2BYcWwatsHbnU76MGRaC25Qfm2ZVgzrGGMq2XbHvhTR-c5LcvXLF-D1B56Yx6TYElqH9akS2C4YbgB56VSQNaacPzPETjB-cjup1GegeArIPMRd5572Z-3dWf-8DiuLJdgyQ9Ww-PojnL9NV65QIlXoHzpsvBm1tDZvhs6F-5h6QqSYq7A2X5N4Gw_GTg388kFxk-EzetMdPmI2QT9VHruvsHdd67UKUlOk07j9D5l6X2GLL2feIcB189lCpR0Hnqux4JzPBK3sCdLkxUAgBRYufo8-bnyHYxXgMTyP_7-9bqgX_xf-sUM9OfKetf5BqflDnakyXL_XNQv4uwd9RBUz0-9ExSO4wd6JXwsva1dnNQ9nTGXC7iZfvhVS8wmJd5RE7f8_byV4MrbqYVrYPxeUuJmDvsPQuIajNeVi4tC8c7kShsIDMaGxZ6yJtbT50g0qajTmkfUJCViVZR5lUb7hqpeVNs0zTPRCYEcu6IusMtyHqd9n2SRbDDGLK7iPMmSOsOF4HlRCuJVSb0oeMKymA5cqoVSPw4LY3eRdG6gJomTuo4jxTtSbuzOEDU9wPiVIYZmzTZh0V037BzL4pDS3bMZL72i5kV6-rfW6oN-KBqsavbeH13IW-PB7KTfD92iNweGm7Dp6d_d0Zo_qfcMNyNUx3Bz4vKjwX8CAAD__-TrTSg">