3

I create a main.cpp in my vscode with clangd enabled, and put the following code in it.

clangd warns the first line with the warning message:

warning: unterminated ‘#pragma pack (push, …)’ at end of file

The whole content of main.cpp:

#pragma pack(push) // warning on this line
#pragma pack(1)
struct A
{
    int   a;
    short b;
    char  c;
};
#pragma pack(pop)

See also: https://releases.llvm.org/13.0.0/tools/clang/docs/DiagnosticsReference.html#wpragma-pack

I think it's a very common usage of #pragma pack(push), I don't understand why the warning is generated.

More strange to me, if I add a semicolon before the first line, the warning disappears.

;                  // Add a semicolon
#pragma pack(push) // The warning disappears
#pragma pack(1)
struct A
{
    int   a;
    short b;
    char  c;
};
#pragma pack(pop)

What's the reason behind?

273K
  • 29,503
  • 10
  • 41
  • 64
xmllmx
  • 39,765
  • 26
  • 162
  • 323

2 Answers2

5

This is a known bug in clangd, tracked in https://github.com/clangd/clangd/issues/1167.

Please see that issue for an explanation of why this currently happens and a potential workaround.

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
0

I'm having the same warning. The semi-colon trick works for me using Qt 6.4 as well. I have no idea why it should.

Colins2
  • 11
  • 3
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33253985) – Osyotr Nov 27 '22 at 15:16