-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Clang] suggest headers on undeclared errors #140247
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,4 +114,5 @@ add_clang_library(clangSema | |
clangEdit | ||
clangLex | ||
clangSupport | ||
) | ||
clangToolingInclusionsStdlib | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,18 @@ void no_get_1() { | |
auto [a0, a1] = A(); // expected-error {{decomposes into 3 elements}} | ||
auto [b0, b1] = B(); // expected-error {{decomposes into 3 elements}} | ||
} | ||
auto [a0, a1, a2] = A(); // expected-error {{undeclared identifier 'get'}} expected-note {{in implicit initialization of binding declaration 'a0'}} | ||
auto [a0, a1, a2] = A(); // expected-error {{undeclared identifier 'get'}} \ | ||
// expected-note {{perhaps `#include <ranges>` is needed?}} \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this does not seem helpful, it feels actively harmful actually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh dear. StdSpecialSymbolMap doesn't even specify the namespace corresponding to get(). Thanks. I didn't know there was such a point. |
||
// expected-note {{in implicit initialization of binding declaration 'a0'}} | ||
} | ||
|
||
int get(A); | ||
|
||
void no_get_2() { | ||
// FIXME: This diagnostic is not great. | ||
auto [a0, a1, a2] = A(); // expected-error {{undeclared identifier 'get'}} expected-note {{in implicit initialization of binding declaration 'a0'}} | ||
auto [a0, a1, a2] = A(); // expected-error {{undeclared identifier 'get'}} \ | ||
// expected-note {{perhaps `#include <ranges>` is needed?}} \ | ||
// expected-note {{in implicit initialization of binding declaration 'a0'}} | ||
} | ||
|
||
template<int> float &get(A); // expected-note 2 {{no known conversion}} | ||
|
@@ -172,7 +176,9 @@ template<int> int get(ADL::X); | |
template<> struct std::tuple_size<ADL::X> { static const int value = 1; }; | ||
template<> struct std::tuple_element<0, ADL::X> { typedef int type; }; | ||
void adl_only_bad() { | ||
auto [x] = ADL::X(); // expected-error {{undeclared identifier 'get'}} expected-note {{in implicit init}} | ||
auto [x] = ADL::X(); // expected-error {{undeclared identifier 'get'}} \ | ||
// expected-note {{perhaps `#include <ranges>` is needed?}} \ | ||
// expected-note {{in implicit init}} | ||
} | ||
|
||
template<typename ElemType, typename GetTypeLV, typename GetTypeRV> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1474,6 +1474,7 @@ namespace cwg387 { // cwg387: 2.8 | |||||
a = gcd(a, b); | ||||||
b = gcd(3, 4); | ||||||
// expected-error@-1 {{use of undeclared identifier 'gcd'}} | ||||||
// expected-note@-2 {{perhaps `#include <numeric>` is needed?}} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -1489,6 +1490,7 @@ namespace cwg387 { // cwg387: 2.8 | |||||
a = gcd(a, b); | ||||||
b = gcd(3, 4); | ||||||
// expected-error@-1 {{use of undeclared identifier 'gcd'}} | ||||||
// expected-note@-2 {{perhaps `#include <numeric>` is needed?}} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
} // namespace cwg387 | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
void f(void) { | ||
int_val2 = 0; // expected-error{{use of undeclared identifier}} | ||
sin(0); // expected-error{{use of undeclared identifier 'sin'}} \ | ||
// expected-note{{perhaps `#include <cmath>` is needed?}} | ||
|
||
std::cout << "Hello world\n"; // expected-error{{use of undeclared identifier 'std'}} \ | ||
// expected-note{{perhaps `#include <iostream>` is needed?}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This note sounds like |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an empty newline at the end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
void f() { | ||
void *p = malloc(sizeof(int) * 10); // expected-error{{use of undeclared identifier 'malloc'}} | ||
void *p = malloc(sizeof(int) * 10); // expected-error{{use of undeclared identifier 'malloc'}} expected-note {{perhaps `#include <cstdlib>` is needed?}} | ||
} | ||
|
||
int malloc(double); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a layering violation, though not a circular dependency. Parser currently does not link against tooling. In your patch, you link tooling into Sema which Parser then picks up transitively. Tooling does not currently link in Parser or Sema, hence no circular dependency.
I kind of think the standard library stuff needs to be lifted into AST. It does seem to rely on
Decl.h
internally, so it can't be lifted into Basic.CC @erichkeane for other opinions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but we want to rewrite anyway. The implementation (StandardLibrary.cpp) seems fairly inefficient. We should try to TableGen a trie and store version information in there, have some support for typo correction, etc