Skip to content

Commit df48e3f

Browse files
committed
Revert "[clang] Pass FoundDecl to DeclRefExpr creator for operator overloads"
This reverts commit 4e94f66. See https://reviews.llvm.org/D129973#3698969 for reasoning.
1 parent 2b0d5e9 commit df48e3f

File tree

6 files changed

+47
-85
lines changed

6 files changed

+47
-85
lines changed

clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,3 @@ template <typename T, template <typename> class U> class Bar {};
210210
// We used to report Q unsued, because we only checked the first template
211211
// argument.
212212
Bar<int, Q> *bar;
213-
214-
namespace internal {
215-
struct S {};
216-
int operator+(S s1, S s2);
217-
}
218-
219-
// Make sure this statement is not reported as unused.
220-
using internal::operator+;
221-
using internal::S;
222-
223-
int j() { return S() + S(); }

clang/lib/Sema/SemaOverload.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ static ExprResult CreateFunctionRefExpr(
6363
// being used.
6464
if (FoundDecl != Fn && S.DiagnoseUseOfDecl(Fn, Loc))
6565
return ExprError();
66-
DeclRefExpr *DRE =
67-
DeclRefExpr::Create(S.Context, Fn->getQualifierLoc(), SourceLocation(),
68-
Fn, false, Loc, Fn->getType(), VK_LValue, FoundDecl);
66+
DeclRefExpr *DRE = new (S.Context)
67+
DeclRefExpr(S.Context, Fn, false, Fn->getType(), VK_LValue, Loc, LocInfo);
6968
if (HadMultipleCandidates)
7069
DRE->setHadMultipleCandidates(true);
7170

clang/test/AST/ast-dump-overloaded-operators.cpp

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,21 @@ void test() {
2424
// CHECK-NEXT: |-FunctionDecl {{.*}} <line:12:1, col:19> col:6{{( imported)?}} used operator, 'void (E, E)'
2525
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:16> col:17{{( imported)?}} 'E'
2626
// CHECK-NEXT: | `-ParmVarDecl {{.*}} <col:18> col:19{{( imported)?}} 'E'
27-
// CHECK-NEXT: |-FunctionDecl {{.*}} <line:14:1, line:18:1> line:14:6{{( imported)?}} test 'void ()'
28-
// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:13, line:18:1>
29-
// CHECK-NEXT: | |-DeclStmt {{.*}} <line:15:3, col:6>
30-
// CHECK-NEXT: | | `-VarDecl {{.*}} <col:3, col:5> col:5{{( imported)?}} used e 'E'
31-
// CHECK-NEXT: | |-CXXOperatorCallExpr {{.*}} <line:16:3, col:7> 'void' '+'
32-
// CHECK-NEXT: | | |-ImplicitCastExpr {{.*}} <col:5> 'void (*)(E, E)' <FunctionToPointerDecay>
33-
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:5> 'void (E, E)' lvalue Function {{.*}} 'operator+' 'void (E, E)'
34-
// CHECK-NEXT: | | |-ImplicitCastExpr {{.*}} <col:3> 'E':'E' <LValueToRValue>
35-
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:3> 'E':'E' lvalue Var {{.*}} 'e' 'E':'E'
36-
// CHECK-NEXT: | | `-ImplicitCastExpr {{.*}} <col:7> 'E':'E' <LValueToRValue>
37-
// CHECK-NEXT: | | `-DeclRefExpr {{.*}} <col:7> 'E':'E' lvalue Var {{.*}} 'e' 'E':'E'
38-
// CHECK-NEXT: | `-CXXOperatorCallExpr {{.*}} <line:17:3, col:7> 'void' ','
39-
// CHECK-NEXT: | |-ImplicitCastExpr {{.*}} <col:5> 'void (*)(E, E)' <FunctionToPointerDecay>
40-
// CHECK-NEXT: | | `-DeclRefExpr {{.*}} <col:5> 'void (E, E)' lvalue Function {{.*}} 'operator,' 'void (E, E)'
41-
// CHECK-NEXT: | |-ImplicitCastExpr {{.*}} <col:3> 'E':'E' <LValueToRValue>
42-
// CHECK-NEXT: | | `-DeclRefExpr {{.*}} <col:3> 'E':'E' lvalue Var {{.*}} 'e' 'E':'E'
43-
// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} <col:7> 'E':'E' <LValueToRValue>
44-
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:7> 'E':'E' lvalue Var {{.*}} 'e' 'E':'E'
45-
46-
namespace a {
47-
void operator-(E, E);
48-
}
49-
50-
using a::operator-;
51-
52-
void f() {
53-
E() - E();
54-
}
55-
// CHECK: |-NamespaceDecl {{.*}} <line:46:1, line:48:1> line:46:11{{( imported <undeserialized declarations>)?}} a
56-
// CHECK-NEXT: | `-FunctionDecl {{.*}} <line:47:3, col:22> col:8{{( imported)?}} used operator- 'void (E, E)'
57-
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:18> col:19{{( imported)?}} 'E'
58-
// CHECK-NEXT: | `-ParmVarDecl {{.*}} <col:21> col:22{{( imported)?}} 'E'
59-
// CHECK-NEXT: |-UsingDecl {{.*}} <line:50:1, col:18> col:10{{( imported)?}} a::operator-
60-
// CHECK-NEXT: |-UsingShadowDecl {{.*}} <col:10> col:10{{( imported)?}} implicit Function {{.*}} 'operator-' 'void (E, E)'
61-
// CHECK-NEXT: `-FunctionDecl {{.*}} <line:52:1, line:54:1> line:52:6{{( imported)?}} f 'void ()'
62-
// CHECK-NEXT: `-CompoundStmt {{.*}} <col:10, line:54:1>
63-
// CHECK-NEXT: `-CXXOperatorCallExpr {{.*}} <line:53:3, col:11> 'void' '-'
64-
// CHECK-NEXT: |-ImplicitCastExpr {{.*}} <col:7> 'void (*)(E, E)' <FunctionToPointerDecay>
65-
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:7> 'void (E, E)' lvalue Function {{.*}} 'operator-' 'void (E, E)' (UsingShadow {{.*}} 'operator-')
66-
// CHECK-NEXT: |-CXXScalarValueInitExpr {{.*}} <col:3, col:5> 'E'
67-
// CHECK-NEXT: `-CXXScalarValueInitExpr {{.*}} <col:9, col:11> 'E'
27+
// CHECK-NEXT: `-FunctionDecl {{.*}} <line:14:1, line:18:1> line:14:6{{( imported)?}} test 'void ()'
28+
// CHECK-NEXT: `-CompoundStmt {{.*}} <col:13, line:18:1>
29+
// CHECK-NEXT: |-DeclStmt {{.*}} <line:15:3, col:6>
30+
// CHECK-NEXT: | `-VarDecl {{.*}} <col:3, col:5> col:5{{( imported)?}} used e 'E'
31+
// CHECK-NEXT: |-CXXOperatorCallExpr {{.*}} <line:16:3, col:7> 'void' '+'
32+
// CHECK-NEXT: | |-ImplicitCastExpr {{.*}} <col:5> 'void (*)(E, E)' <FunctionToPointerDecay>
33+
// CHECK-NEXT: | | `-DeclRefExpr {{.*}} <col:5> 'void (E, E)' lvalue Function {{.*}} 'operator+' 'void (E, E)'
34+
// CHECK-NEXT: | |-ImplicitCastExpr {{.*}} <col:3> 'E':'E' <LValueToRValue>
35+
// CHECK-NEXT: | | `-DeclRefExpr {{.*}} <col:3> 'E':'E' lvalue Var {{.*}} 'e' 'E'
36+
// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} <col:7> 'E':'E' <LValueToRValue>
37+
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:7> 'E':'E' lvalue Var {{.*}} 'e' 'E'
38+
// CHECK-NEXT: `-CXXOperatorCallExpr {{.*}} <line:17:3, col:7> 'void' ','
39+
// CHECK-NEXT: |-ImplicitCastExpr {{.*}} <col:5> 'void (*)(E, E)' <FunctionToPointerDecay>
40+
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:5> 'void (E, E)' lvalue Function {{.*}} 'operator,' 'void (E, E)'
41+
// CHECK-NEXT: |-ImplicitCastExpr {{.*}} <col:3> 'E':'E' <LValueToRValue>
42+
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:3> 'E':'E' lvalue Var {{.*}} 'e' 'E'
43+
// CHECK-NEXT: `-ImplicitCastExpr {{.*}} <col:7> 'E':'E' <LValueToRValue>
44+
// CHECK-NEXT: `-DeclRefExpr {{.*}} <col:7> 'E':'E' lvalue Var {{.*}} 'e' 'E'

clang/test/Index/annotate-operator-call-expr.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,68 +17,68 @@ void testFoo(Foo foo, int index) {
1717

1818
// RUN: c-index-test -test-annotate-tokens=%s:7:1:7:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK1
1919
// CHECK1: Identifier: "foo" [7:3 - 7:6] DeclRefExpr=foo:6:18
20-
// CHECK1: Punctuation: "(" [7:6 - 7:7] CallExpr=operator():3:7
21-
// CHECK1: Punctuation: ")" [7:7 - 7:8] CallExpr=operator():3:7
20+
// CHECK1: Punctuation: "(" [7:6 - 7:7] DeclRefExpr=operator():3:7 RefName=[7:6 - 7:7] RefName=[7:7 - 7:8]
21+
// CHECK1: Punctuation: ")" [7:7 - 7:8] DeclRefExpr=operator():3:7 RefName=[7:6 - 7:7] RefName=[7:7 - 7:8]
2222
// CHECK1: Punctuation: ";" [7:8 - 7:9] CompoundStmt=
2323

2424
// RUN: c-index-test -test-annotate-tokens=%s:8:1:8:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK2
25-
// CHECK2: Punctuation: "(" [8:6 - 8:7] CallExpr=operator():3:7
25+
// CHECK2: Punctuation: "(" [8:6 - 8:7] DeclRefExpr=operator():3:7 RefName=[8:6 - 8:7] RefName=[8:12 - 8:13]
2626
// CHECK2: Identifier: "index" [8:7 - 8:12] DeclRefExpr=index:6:27
27-
// CHECK2: Punctuation: ")" [8:12 - 8:13] CallExpr=operator():3:7
27+
// CHECK2: Punctuation: ")" [8:12 - 8:13] DeclRefExpr=operator():3:7 RefName=[8:6 - 8:7] RefName=[8:12 - 8:13]
2828
// CHECK2: Punctuation: ";" [8:13 - 8:14] CompoundStmt=
2929

3030
// RUN: c-index-test -test-annotate-tokens=%s:10:1:10:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK3
3131
// CHECK3: Identifier: "foo" [10:3 - 10:6] DeclRefExpr=foo:6:18
32-
// CHECK3: Punctuation: "[" [10:6 - 10:7] CallExpr=operator[]:2:7
32+
// CHECK3: Punctuation: "[" [10:6 - 10:7] DeclRefExpr=operator[]:2:7 RefName=[10:6 - 10:7] RefName=[10:12 - 10:13]
3333
// CHECK3: Identifier: "index" [10:7 - 10:12] DeclRefExpr=index:6:27
34-
// CHECK3: Punctuation: "]" [10:12 - 10:13] CallExpr=operator[]:2:7
34+
// CHECK3: Punctuation: "]" [10:12 - 10:13] DeclRefExpr=operator[]:2:7 RefName=[10:6 - 10:7] RefName=[10:12 - 10:13]
3535
// CHECK3: Punctuation: ";" [10:13 - 10:14] CompoundStmt=
3636

3737
// RUN: c-index-test -test-annotate-tokens=%s:11:1:11:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK4
3838
// CHECK4: Identifier: "foo" [11:3 - 11:6] DeclRefExpr=foo:6:18
39-
// CHECK4: Punctuation: "[" [11:6 - 11:7] CallExpr=operator[]:2:7
39+
// CHECK4: Punctuation: "[" [11:6 - 11:7] DeclRefExpr=operator[]:2:7 RefName=[11:6 - 11:7] RefName=[11:20 - 11:21]
4040
// CHECK4: Identifier: "index" [11:7 - 11:12] DeclRefExpr=index:6:27
4141
// CHECK4: Punctuation: "+" [11:13 - 11:14] BinaryOperator=
4242
// CHECK4: Identifier: "index" [11:15 - 11:20] DeclRefExpr=index:6:27
43-
// CHECK4: Punctuation: "]" [11:20 - 11:21] CallExpr=operator[]:2:7
43+
// CHECK4: Punctuation: "]" [11:20 - 11:21] DeclRefExpr=operator[]:2:7 RefName=[11:6 - 11:7] RefName=[11:20 - 11:21]
4444
// CHECK4: Punctuation: ";" [11:21 - 11:22] CompoundStmt=
4545

4646
// RUN: c-index-test -test-annotate-tokens=%s:13:1:13:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK5
4747
// CHECK5: Identifier: "foo" [13:3 - 13:6] DeclRefExpr=foo:6:18
48-
// CHECK5: Punctuation: "[" [13:6 - 13:7] CallExpr=operator[]:2:7
48+
// CHECK5: Punctuation: "[" [13:6 - 13:7] DeclRefExpr=operator[]:2:7 RefName=[13:6 - 13:7] RefName=[13:17 - 13:18]
4949
// CHECK5: Identifier: "foo" [13:7 - 13:10] DeclRefExpr=foo:6:18
50-
// CHECK5: Punctuation: "[" [13:10 - 13:11] CallExpr=operator[]:2:7
50+
// CHECK5: Punctuation: "[" [13:10 - 13:11] DeclRefExpr=operator[]:2:7 RefName=[13:10 - 13:11] RefName=[13:16 - 13:17]
5151
// CHECK5: Identifier: "index" [13:11 - 13:16] DeclRefExpr=index:6:27
52-
// CHECK5: Punctuation: "]" [13:16 - 13:17] CallExpr=operator[]:2:7
53-
// CHECK5: Punctuation: "]" [13:17 - 13:18] CallExpr=operator[]:2:7
52+
// CHECK5: Punctuation: "]" [13:16 - 13:17] DeclRefExpr=operator[]:2:7 RefName=[13:10 - 13:11] RefName=[13:16 - 13:17]
53+
// CHECK5: Punctuation: "]" [13:17 - 13:18] DeclRefExpr=operator[]:2:7 RefName=[13:6 - 13:7] RefName=[13:17 - 13:18]
5454
// CHECK5: Punctuation: ";" [13:18 - 13:19] CompoundStmt=
5555

5656
// RUN: c-index-test -test-annotate-tokens=%s:14:1:14:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK6
5757
// CHECK6: Identifier: "foo" [14:3 - 14:6] DeclRefExpr=foo:6:18
58-
// CHECK6: Punctuation: "[" [14:6 - 14:7] CallExpr=operator[]:2:7
58+
// CHECK6: Punctuation: "[" [14:6 - 14:7] DeclRefExpr=operator[]:2:7 RefName=[14:6 - 14:7] RefName=[14:25 - 14:26]
5959
// CHECK6: Identifier: "foo" [14:7 - 14:10] DeclRefExpr=foo:6:18
60-
// CHECK6: Punctuation: "(" [14:10 - 14:11] CallExpr=operator():3:7
61-
// CHECK6: Punctuation: ")" [14:11 - 14:12] CallExpr=operator():3:7
60+
// CHECK6: Punctuation: "(" [14:10 - 14:11] DeclRefExpr=operator():3:7 RefName=[14:10 - 14:11] RefName=[14:11 - 14:12]
61+
// CHECK6: Punctuation: ")" [14:11 - 14:12] DeclRefExpr=operator():3:7 RefName=[14:10 - 14:11] RefName=[14:11 - 14:12]
6262
// CHECK6: Punctuation: "+" [14:13 - 14:14] BinaryOperator=
6363
// CHECK6: Identifier: "foo" [14:15 - 14:18] DeclRefExpr=foo:6:18
64-
// CHECK6: Punctuation: "[" [14:18 - 14:19] CallExpr=operator[]:2:7
65-
// CHECK6: Identifier: "index" [14:19 - 14:24] DeclRefExpr=index:6:27
66-
// CHECK6: Punctuation: "]" [14:24 - 14:25] CallExpr=operator[]:2:7
67-
// CHECK6: Punctuation: "]" [14:25 - 14:26] CallExpr=operator[]:2:7
64+
// CHECK6: Punctuation: "[" [14:18 - 14:19] DeclRefExpr=operator[]:2:7 RefName=[14:18 - 14:19] RefName=[14:24 - 14:25]
65+
// CHECK6: Identifier: "index" [14:19 - 14:24] DeclRefExpr=operator[]:2:7 RefName=[14:6 - 14:7] RefName=[14:25 - 14:26]
66+
// CHECK6: Punctuation: "]" [14:24 - 14:25] DeclRefExpr=operator[]:2:7 RefName=[14:18 - 14:19] RefName=[14:24 - 14:25]
67+
// CHECK6: Punctuation: "]" [14:25 - 14:26] DeclRefExpr=operator[]:2:7 RefName=[14:6 - 14:7] RefName=[14:25 - 14:26]
6868
// CHECK6: Punctuation: ";" [14:26 - 14:27] CompoundStmt=
6969

7070
// RUN: c-index-test -test-annotate-tokens=%s:15:1:15:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK7
7171
// CHECK7: Identifier: "foo" [15:3 - 15:6] DeclRefExpr=foo:6:18
72-
// CHECK7: Punctuation: "[" [15:6 - 15:7] CallExpr=operator[]:2:7
72+
// CHECK7: Punctuation: "[" [15:6 - 15:7] DeclRefExpr=operator[]:2:7 RefName=[15:6 - 15:7] RefName=[15:30 - 15:31]
7373
// CHECK7: Identifier: "foo" [15:7 - 15:10] DeclRefExpr=foo:6:18
74-
// CHECK7: Punctuation: "(" [15:10 - 15:11] CallExpr=operator():3:7
74+
// CHECK7: Punctuation: "(" [15:10 - 15:11] DeclRefExpr=operator():3:7 RefName=[15:10 - 15:11] RefName=[15:16 - 15:17]
7575
// CHECK7: Identifier: "index" [15:11 - 15:16] DeclRefExpr=index:6:27
76-
// CHECK7: Punctuation: ")" [15:16 - 15:17] CallExpr=operator():3:7
76+
// CHECK7: Punctuation: ")" [15:16 - 15:17] DeclRefExpr=operator():3:7 RefName=[15:10 - 15:11] RefName=[15:16 - 15:17]
7777
// CHECK7: Punctuation: "+" [15:18 - 15:19] BinaryOperator=
7878
// CHECK7: Identifier: "foo" [15:20 - 15:23] DeclRefExpr=foo:6:18
79-
// CHECK7: Punctuation: "[" [15:23 - 15:24] CallExpr=operator[]:2:7
79+
// CHECK7: Punctuation: "[" [15:23 - 15:24] DeclRefExpr=operator[]:2:7 RefName=[15:23 - 15:24] RefName=[15:29 - 15:30]
8080
// CHECK7: Identifier: "index" [15:24 - 15:29] DeclRefExpr=index:6:27
81-
// CHECK7: Punctuation: "]" [15:29 - 15:30] CallExpr=operator[]:2:7
82-
// CHECK7: Punctuation: "]" [15:30 - 15:31] CallExpr=operator[]:2:7
81+
// CHECK7: Punctuation: "]" [15:29 - 15:30] DeclRefExpr=operator[]:2:7 RefName=[15:23 - 15:24] RefName=[15:29 - 15:30]
82+
// CHECK7: Punctuation: "]" [15:30 - 15:31] DeclRefExpr=operator[]:2:7 RefName=[15:6 - 15:7] RefName=[15:30 - 15:31]
8383
// CHECK7: Punctuation: ";" [15:31 - 15:32] CompoundStmt=
8484

clang/test/Index/cursor-ref-names.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ int main()
3333
// CHECK: cursor-ref-names.cpp:18:5: CallExpr=func:8:10 Extent=[18:5 - 18:16]
3434
// CHECK: cursor-ref-names.cpp:18:10: MemberRefExpr=func:8:10 SingleRefName=[18:10 - 18:14] RefName=[18:10 - 18:14] Extent=[18:5 - 18:14]
3535
// CHECK: cursor-ref-names.cpp:18:5: DeclRefExpr=inst:17:9 Extent=[18:5 - 18:9]
36-
// CHECK: cursor-ref-names.cpp:19:5: CallExpr=operator[]:4:9{{(\Q SingleRefName=[19:9 - 19:12] RefName=[19:9 - 19:10] RefName=[19:11 - 19:12]\E)?}} Extent=[19:5 - 19:12]
36+
// CHECK: cursor-ref-names.cpp:19:5: CallExpr=operator[]:4:9 SingleRefName=[19:9 - 19:12] RefName=[19:9 - 19:10] RefName=[19:11 - 19:12] Extent=[19:5 - 19:12]
3737
// CHECK: cursor-ref-names.cpp:19:5: DeclRefExpr=inst:17:9 Extent=[19:5 - 19:9]
38-
// CHECK: cursor-ref-names.cpp:19:9: DeclRefExpr=operator[]:4:9 Extent=[19:9 - 19:10]
38+
// CHECK: cursor-ref-names.cpp:19:9: DeclRefExpr=operator[]:4:9 RefName=[19:9 - 19:10] RefName=[19:11 - 19:12] Extent=[19:9 - 19:12]
3939
// CHECK: cursor-ref-names.cpp:20:5: CallExpr=operator[]:4:9 Extent=[20:5 - 20:23]
4040
// CHECK: cursor-ref-names.cpp:20:10: MemberRefExpr=operator[]:4:9 SingleRefName=[20:10 - 20:20] RefName=[20:10 - 20:18] RefName=[20:18 - 20:19] RefName=[20:19 - 20:20] Extent=[20:5 - 20:20]
4141
// CHECK: cursor-ref-names.cpp:20:5: DeclRefExpr=inst:17:9 Extent=[20:5 - 20:9]

clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4681,9 +4681,6 @@ TEST(UsingDeclaration, ThroughUsingDeclaration) {
46814681
EXPECT_TRUE(notMatches(
46824682
"namespace a { void f(); } using a::f; void g() { a::f(); }",
46834683
declRefExpr(throughUsingDecl(anything()))));
4684-
EXPECT_TRUE(matches("struct S {}; namespace a { int operator+(S s1, S s2); } "
4685-
"using a::operator+; int g() { return S() + S(); }",
4686-
declRefExpr(throughUsingDecl(anything()))));
46874684
}
46884685

46894686
TEST(SingleDecl, IsSingleDecl) {

0 commit comments

Comments
 (0)