Skip to content

Suggest include file for popular standard functions #120388

@tbaederr

Description

@tbaederr

If, e.g. write:

int main() {
  std::cout << "Hello world\n";
}

I think it would be nice for the compiler to suggest importing <iostream>. If I later write

#include <iostream>
int main() {
  std::cout << "Hello world\n";

  int a = 0, b = 0;
  std::memcpy(&a, &b, 4);
}

it would be nice if it suggested importing <cstring>. I think a simple internal list of popular functions would be enough, we don't need to get fancy here.

I don't know if this collides with functionality that clangd or similar tools already provide though.

Popular D compilers have similar functionality:

~ » cat test.d
void main() {
  writeln("hello world");
}

~ » ldc2 test.d
test.d(7): Error: `writeln` is not defined, perhaps `import std.stdio;` is needed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"enhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions