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

[C++][IWYU] How to treat includes in case of compiler deduction? #863

Open
marcogmaia opened this issue Nov 13, 2024 · 0 comments
Open

[C++][IWYU] How to treat includes in case of compiler deduction? #863

marcogmaia opened this issue Nov 13, 2024 · 0 comments
Labels
lang:cpp The C++ language

Comments

@marcogmaia
Copy link

marcogmaia commented Nov 13, 2024

I have a question about header inclusion best practices when dealing with implicit type construction.

Consider the following code structure:

// a.h 
struct A { int x, y; };

// b.h 
#include "a.h"

struct B { void Func(A a) { /* use a */ } };

// c.cpp 
#include "b.h" 

void Func() { 
  B b; 
  b.Func({1, 2}); // Implicit construction of A 
}

In c.cpp, we're using struct A implicitly through brace initialization, and the compiler successfully deduces the type for us because b.h includes a.h. This pattern is common when working with aggregate types.

Questions:

  • Should we explicitly include a.h in c.cpp even though we're not directly referencing the symbol?
  • What's the general consensus for header inclusion when dealing with implicit type construction?

I'd appreciate insights on this scenario.

@vapier vapier added the lang:cpp The C++ language label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:cpp The C++ language
Projects
None yet
Development

No branches or pull requests

2 participants