Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] "unknown pragma ignored" generated on "pragma pack" in c++20 mode #67380

Closed
vient opened this issue Sep 25, 2023 · 5 comments
Closed

Comments

@vient
Copy link
Member

vient commented Sep 25, 2023

Source test.cpp

#pragma pack(1)
struct S {};

Compiling with clang++-17 -Wall -Werror -std=c++20 -o test.o -c test.cpp works fine, no errors.

I created /tmp/test/compile_commands.json using -MJ clang option output:

[
  {
    "directory": "/tmp/test",
    "file": "test.cpp",
    "output": "test.o",
    "arguments": [
      "/usr/lib/llvm-17/bin/clang",
      "-xc++",
      "test.cpp",
      "-o",
      "test.o",
      "--driver-mode=g++",
      "-Wall",
      "-Werror",
      "-std=c++20",
      "-c",
      "--target=x86_64-pc-linux-gnu"
    ]
  }
]

Running clang-tidy-17 test.cpp in /tmp/test folder produces following output

$ clang-tidy-17 test.cpp
1 error generated.
Error while processing /tmp/test/test.cpp.
test.cpp:1:9: error: unknown pragma ignored [clang-diagnostic-unknown-pragmas]
    1 | #pragma pack(1)
      |         ^
Found compiler error(s).

Error is only produced in c++20 and newer modes, like c++2b, but not in c++17 or older.

I am using latest 17 build from LLVM apt repo

$ clang++-17 --version
Ubuntu clang version 17.0.2 (++20230925113614+481358974fb0-1~exp1~20230925113629.44)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang-tidy-17 --version
Ubuntu LLVM version 17.0.2
  Optimized build.
@vient
Copy link
Member Author

vient commented Sep 25, 2023

Can't get this error on CE https://godbolt.org/z/4vPYY6aY4, does it mean that this is not present in trunk?

@PiotrZSL
Copy link
Member

Got it with:

clang-tidy-17 test.cpp --extra-arg=-std=c++20
1 warning generated.
/fpwork/llvm-project/test.cpp:1:9: warning: unknown pragma ignored [clang-diagnostic-unknown-pragmas]
    1 | #pragma pack(1)
      |         ^

or

clang-tidy-17 test.cpp -- -std=c++20 -Wall
1 warning generated.
/fpwork/llvm-project/test.cpp:1:9: warning: unknown pragma ignored [clang-diagnostic-unknown-pragmas]
    1 | #pragma pack(1)
      |         ^

With trunk version is reproduced only when '--enable-module-headers-parsing' is used.
This is known issue caused by two preprocessors created for C++20 and above.
This functionality is disabled by default in clang-tidy 18.

@vient
Copy link
Member Author

vient commented Sep 30, 2023

Ok, thanks for info, added this to my .clang-tidy

ExtraArgs:
- -Wno-unknown-pragmas  # TODO: remove this after switch to clang-tidy-18

@vient vient closed this as completed Sep 30, 2023
@spt29
Copy link

spt29 commented Oct 18, 2023

Is this the fix? 992fa7b Any chance of a backport into the 17.x release branch?

@PiotrZSL
Copy link
Member

More this would be a workaround: b530eee
And I think there is zero chance to get this backported.

fanquake added a commit to fanquake/bitcoin that referenced this issue Mar 14, 2024
This is a bug in LLVM 17 when compiling for C++20.
Should be fixed in 18.
See llvm/llvm-project#67380.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants