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

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] MSVC's Pragma packed not expanded correctly in structs
        </td>
    </tr>

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

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

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

<pre>
    When applying pragma packed in a struct definition, clang-tidy gives the following error:
Declaration of anonymous struct must be a definition - clang(anon_type_definition)
Declaration does not declare anything - clang(-Wmissing-declarations)

You can easily reproduce the error with the following code:

```#include <cstdint>

#ifdef __GNUC__
#if __cplusplus >= 201103L
#define __begin_packed [[gnu::packed]]
#else
#define __begin_packed __attribute__((packed))
#endif
#define __end_packed
#else // MSVC
#define __begin_packed __pragma(pack(push, 1))
#define __end_packed   __pragma(pack(pop))
#endif

struct Normal {
 uint8_t a;
    uint32_t b;
};

struct __pragma(pack(push, 1)) Packed {
    uint8_t a;
    uint32_t b;
} __end_packed;

struct After {
    uint8_t a;
    uint32_t b;
};

int main() {
    static_assert(sizeof(struct Normal) == 8);
    static_assert(sizeof(struct Packed) == 5);
 static_assert(sizeof(struct After) == 8);
}```

This only happens for MSVC, despite the code compiling and behaving correctly. In Visual Studio, with their static analysis, it does not even display an error. The error does not occur with the following code:

```
__pragma(pack(push, 1))
struct Packed {
    uint8_t a;
    uint32_t b;
} __end_packed;
```

And the behavior is as expected. It only occurs if `pragma` is placed right after `struct`. The way I'm using it may be obtuse, but that is a way to guarantee the same behavior accross GCC-based compilers and MSVC.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk2P2zYQ_TX0ZWBDorz-OPiwsbNBgCYIkDRBTwIljiW2FClwyN2ov74gJX9ttt20KOCVtCPOm3kzjyMKItUYxB27e8PuDjMRfGvd7q0MH9A0SLPK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