Skip to content

Commit 40f5335

Browse files
authored
Merge pull request #2917 from WalterBright/FunctionOverloading
improve Function Overloading section
2 parents fc70113 + 196fd76 commit 40f5335

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

spec/function.dd

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,10 @@ $(H2 $(LNAME2 inline-functions, Inline Functions))
11031103

11041104
$(H2 $(LNAME2 function-overloading, Function Overloading))
11051105

1106-
$(P Functions are overloaded based on how well the arguments
1107-
to a function can match up with the parameters.
1108-
The function with the $(I best) match is selected.
1109-
The levels of matching are:
1106+
$(P $(I Function overloading) occurs when two or more functions in the same scope
1107+
have the same name.
1108+
The function selected is the one that is the $(I best match) to the arguments.
1109+
The matching levels are:
11101110
)
11111111

11121112
$(OL
@@ -1117,27 +1117,26 @@ $(H2 $(LNAME2 function-overloading, Function Overloading))
11171117
$(LI exact match)
11181118
)
11191119

1120-
$(P Each argument (including any $(CODE this) pointer) is
1121-
compared against the function's corresponding parameter, to
1120+
$(P Each argument (including any $(CODE this) reference) is
1121+
compared against the function's corresponding parameter to
11221122
determine the match level for that argument. The match level
11231123
for a function is the $(I worst) match level of each of its
11241124
arguments.)
11251125

11261126
$(P Literals do not match $(CODE ref) or $(CODE out) parameters.)
11271127

1128-
11291128
$(P If two or more functions have the same match level,
11301129
then $(LNAME2 partial-ordering, $(I partial ordering))
1131-
is used to try to find the best match.
1130+
is used to disambiguate to find the best match.
11321131
Partial ordering finds the most specialized function.
11331132
If neither function is more specialized than the other,
11341133
then it is an ambiguity error.
1135-
Partial ordering is determined for functions $(CODE f())
1136-
and $(CODE g()) by taking the parameter types of $(CODE f()),
1134+
Partial ordering is determined for functions $(I f)
1135+
and $(I g) by taking the parameter types of $(I f),
11371136
constructing a list of arguments by taking the default values
1138-
of those types, and attempting to match them against $(CODE g()).
1139-
If it succeeds, then $(CODE g()) is at least as specialized
1140-
as $(CODE f()).
1137+
of those types, and attempting to match them against $(I g).
1138+
If it succeeds, then $(I g) is at least as specialized
1139+
as $(I f).
11411140
For example:
11421141
)
11431142
---
@@ -1150,7 +1149,7 @@ void foo(B);
11501149
void test()
11511150
{
11521151
C c;
1153-
/* Both foo(A) and foo(B) match with implicit conversion rules.
1152+
/* Both foo(A) and foo(B) match with implicit conversions (level 2).
11541153
* Applying partial ordering rules,
11551154
* foo(B) cannot be called with an A, and foo(A) can be called
11561155
* with a B. Therefore, foo(B) is more specialized, and is selected.
@@ -1163,16 +1162,11 @@ void test()
11631162
)
11641163

11651164

1166-
$(P Functions defined with non-D linkage cannot be overloaded.
1167-
This is because the name mangling might not take the parameter types
1168-
into account.
1169-
)
1170-
11711165
$(H3 $(LNAME2 overload-sets, Overload Sets))
11721166

11731167
$(P Functions declared at the same scope overload against each
11741168
other, and are called an $(I Overload Set).
1175-
A typical example of an overload set are functions defined
1169+
An example of an overload set are functions defined
11761170
at module level:
11771171
)
11781172

@@ -1185,7 +1179,8 @@ void foo(long i) { }
11851179
)
11861180

11871181
$(P $(CODE A.foo()) and $(CODE A.foo(long)) form an overload set.
1188-
A different module can also define functions with the same name:
1182+
A different module can also define another overload set of
1183+
functions with the same name:
11891184
)
11901185

11911186
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
@@ -1199,7 +1194,8 @@ void foo(int i) { }
11991194

12001195
$(P and A and B can be imported by a third module, C.
12011196
Both overload sets, the $(CODE A.foo) overload set and the $(CODE B.foo)
1202-
overload set, are found. An instance of $(CODE foo) is selected
1197+
overload set, are found when searching for symbol `foo`.
1198+
An instance of $(CODE foo) is selected
12031199
based on it matching in exactly one overload set:
12041200
)
12051201

@@ -1244,6 +1240,7 @@ void bar(C c)
12441240
}
12451241
---
12461242

1243+
12471244
$(H2 $(LNAME2 parameters, Function Parameters))
12481245

12491246
$(H3 $(LNAME2 param-storage, Parameter Storage Classes))

0 commit comments

Comments
 (0)