Skip to content

Commit 5f6dbd2

Browse files
committed
Interpret using declarations in a class as a possible overload
1 parent 4c2a88e commit 5f6dbd2

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

robotpy_build/autowrap/cxxparser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ def on_using_declaration(self, state: AWState, using: UsingDecl) -> None:
451451

452452
if using.access is None:
453453
self.hctx.using_declarations.append(using.typename)
454+
elif isinstance(state, ClassBlockState):
455+
# A using declaration might bring in a colliding name for a function,
456+
# so mark it as overloaded
457+
lseg = using.typename.segments[-1]
458+
if isinstance(lseg, NameSpecifier):
459+
cdata = state.user_data
460+
name = lseg.name
461+
self.gendata.add_using_decl(
462+
name, cdata.cls_key, cdata.data, state.access == "private"
463+
)
454464

455465
#
456466
# Enums

robotpy_build/autowrap/generator_data.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ def get_function_data(
145145
report_data.tracker.add_overload()
146146
return data, report_data.tracker
147147

148+
def add_using_decl(
149+
self, name: str, cls_key: str, cls_data: ClassData, is_private: bool
150+
):
151+
# copied from get_function_data
152+
data = cls_data.methods.get(name)
153+
report_base = self.classes[cls_key].functions
154+
155+
report_data = report_base.get(name)
156+
if not report_data:
157+
report_data = FnReportData()
158+
report_base[name] = report_data
159+
160+
missing = data is None
161+
report_data.missing = missing and not is_private
162+
163+
# We count this as an overload because it might be
164+
report_data.tracker.add_overload()
165+
148166
def get_cls_prop_data(
149167
self, name: str, cls_key: str, cls_data: ClassData
150168
) -> PropData:

tests/cpp/rpytest/ft/include/using2.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,16 @@ struct Using4 {
3535
int getX(const FwdDecl&);
3636
};
3737

38+
struct Using5a {
39+
virtual ~Using5a() {}
40+
void fn(int arg) {}
41+
};
42+
43+
struct Using5b : Using5a {
44+
// this collides but isn't picked up without interpreting the using
45+
using Using5a::fn;
46+
void fn(bool arg) {}
47+
};
48+
3849
} // namespace u2
3950
} // namespace u

0 commit comments

Comments
 (0)