Skip to content

-isystem does not suppress warnings from macros #129746

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

Open
elbeno opened this issue Mar 4, 2025 · 0 comments
Open

-isystem does not suppress warnings from macros #129746

elbeno opened this issue Mar 4, 2025 · 0 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@elbeno
Copy link

elbeno commented Mar 4, 2025

Given a header provoke_warning.hpp:

enum struct E { A, B, C };

namespace N {
  using enum E;
}

#define PROVOKE_WARNING using enum E;

And a source file main.cpp:

#include <provoke_warning.hpp>

struct S {
  PROVOKE_WARNING;
};

When compile with:
clang -std=c++17 -isystem . -c main.cpp

We get:

main.cpp:4:3: warning: using enum declaration is a C++20 extension [-Wc++20-extensions]
    4 |   PROVOKE_WARNING;
      |   ^
./provoke_warning.hpp:7:31: note: expanded from macro 'PROVOKE_WARNING'
    7 | #define PROVOKE_WARNING using enum E;
      |                               ^                                

Notice that the warning we would get from the using enum inside the namespace is not emitted (because of -isystem). However the use of the macro still gives a warning despite the fact that the macro came from a header included under -isystem.

--

I see why this could be difficult to remedy, and I already see the counterarguments: "it's a macro! It's in your code, not the library code!" So it's understandable why this happens, but that doesn't make it correct or expected.

This comes up in real code: catchorg/Catch2#2910

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

3 participants