Skip to content

Large number of -Wattributes warnings when compiled with GCC >= 14 #157834

@mstorsjo

Description

@mstorsjo

If compiling Clang with GCC 14 or newer (for Linux), the build produces a very large number of warnings - obscuring any other potential higher value warnings. Building with GCC seldom is warning free anyway, but ideally we'd keep it at least in manageable numbers.

There are around 600 instances of the same warning:

/build/llvm-project/clang/include/clang/Sema/Sema.h:841:7: warning: 'clang::Sema' declared with greater visibility than the type of its field 'clang::Sema::UnusedFileScopedDecls' [-Wattributes]
  841 | class Sema : public SemaBase {
      |       ^~~~
/build/llvm-project/clang/include/clang/Sema/Sema.h:841:7: warning: 'clang::Sema' declared with greater visibility than the type of its field 'clang::Sema::TentativeDefinitions' [-Wattributes]
/build/llvm-project/clang/include/clang/Sema/Sema.h:841:7: warning: 'clang::Sema' declared with greater visibility than the type of its field 'clang::Sema::ExtVectorDecls' [-Wattributes]
/build/llvm-project/clang/include/clang/Sema/Sema.h:841:7: warning: 'clang::Sema' declared with greater visibility than the type of its field 'clang::Sema::DelegatingCtorDecls' [-Wattributes]

(I.e this header gets included in 150 translation units, and each time it produces 4 warnings.)

In principle, this warning actually seems legitimate in this case. The warning is caused by us building with -fvisibility-inlines-hidden. The root cause of the issue can be observed in this reduced testcase:

class SomeClass {
public:
    void method() {}
};

template<typename Source, void (Source::*Loader)()>
class LazyVector { };

class TestClass {
  typedef LazyVector<SomeClass, &SomeClass::method> MyType;
  MyType vect;
};
$ g++-14 -c repro.cpp -Wextra -fvisibility-inlines-hidden
repro.cpp:9:7: warning: ‘TestClass’ declared with greater visibility than the type of its field ‘TestClass::vect’ [-Wattributes]
    9 | class TestClass {
      |       ^~~~~~~~~

https://gcc.godbolt.org/z/vhfcoaeoc

Now while the warning seems legitimate in its own right, it's probably not an issue we'd like to deal with here. Unfortunately, it seems to be stuck behind a very wide warning option - turning off all warnings about attributes seems like a very large hammer. But 600 warnings during the build is also quite unmanageable.

CC @MaskRay @firewave @DavidSpickett @tstellar @nikic

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"code-quality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions