Skip to content

Commit 391b80e

Browse files
committed
C++: Show virtual inheritance problem in vdispatch
1 parent 2a0fc31 commit 391b80e

File tree

1 file changed

+23
-0
lines changed
  • cpp/ql/test/library-tests/dataflow/dataflow-tests

1 file changed

+23
-0
lines changed

cpp/ql/test/library-tests/dataflow/dataflow-tests/dispatch.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,26 @@ void testFunctionPointer(SinkFunctionType maybeCallSink, SinkFunctionType dontCa
107107
maybeCallSink(source()); // flow [NOT DETECTED by AST]
108108
dontCallSink(source()); // no flow
109109
}
110+
111+
namespace virtual_inheritance {
112+
struct Top {
113+
virtual int isSource() { return 0; }
114+
};
115+
116+
struct Middle : virtual Top {
117+
int isSource() override { return source(); }
118+
};
119+
120+
struct Bottom : Middle {
121+
};
122+
123+
void VirtualDispatch(Bottom *bottomPtr, Bottom &bottomRef) {
124+
// Because the inheritance from `Top` is virtual, the following casts go
125+
// directly from `Bottom` to `Top`, skipping `Middle`. That means we don't
126+
// get flow from a `Middle` value to the call qualifier.
127+
Top *topPtr = bottomPtr, &topRef = bottomRef;
128+
129+
sink(topPtr->isSource()); // flow [NOT DETECTED]
130+
sink(topRef.isSource()); // flow [NOT DETECTED]
131+
}
132+
}

0 commit comments

Comments
 (0)