llvm / llvm/llvm-project

Split redefine_extname out of -Wpragmas

Open
#187,497 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Right now, many warnings are controlled by -Wpragmas itself, but #pragma redefine_extname's warning can over-occur in code bases easily.

#pragma redefine_extname foo bar

// ...

namespace x {
    void foo() {}
}

prints:

<source>:6:10: warning: #pragma redefine_extname is applicable to external C declarations only; not applied to function 'foo' [-Wpragmas]
    6 |     void foo() {}
      |          ^

See https://godbolt.org/z/hGsdhaWWM.

When this is intentional, the only way to turn off the warning is to turn the warning down (from a -Werror starting point) at the definition site of foo using:

#pragma GCC diagnostic warning "-Wpragmas"

However, this requires touching the definition sites, which don't even have pragmas, so this is kinda weird.

But as I personally do not even see a point in this warning (we intend to only affect external C symbols after all), I would like to turn it off (or down from error to warning) without affecting all the rest in -Wpragmas. So best would be getting a specific flag for just this one.

A slightly different option would be if the warning could be "back-dated" to the #pragma redefine_extname line (and also be affected by the pushed/popped diagnostics state from there). Then we could disable it in a targeted manner without affecting everything else.

Any ideas?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Clang handles #pragma redefine_extname diagnostics and how that warning is grouped under -Wpragmas. Compare the separate-warning and back-dated-diagnostic options described in the issue; done means one targeted behavior is implemented and covered by relevant compiler diagnostic tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.