in src/checks/manuallevel/qt6-fwd-fixes.cpp [88:148]
void Qt6FwdFixes::VisitDecl(clang::Decl *decl)
{
auto *recDecl = dyn_cast<CXXRecordDecl>(decl);
if (!recDecl) {
return;
}
auto *parent = recDecl->getParent();
std::string parentType = parent->getDeclKindName();
if (parentType != "TranslationUnit") {
return;
}
if (recDecl->hasDefinition()) {
return;
}
if (interestingFwdDecl.find(recDecl->getNameAsString()) == interestingFwdDecl.end()) {
return;
}
const std::string currentFile = m_sm.getFilename(decl->getLocation()).str();
if (m_currentFile != currentFile) {
m_currentFile = currentFile;
m_including_qcontainerfwd = false;
if (m_qcontainerfwd_included_in_files.find(currentFile) != m_qcontainerfwd_included_in_files.end()) {
m_including_qcontainerfwd = true;
}
}
SourceLocation endLoc = locForNextSemiColon(recDecl->getBeginLoc(), m_sm, lo());
SourceLocation beginLoc;
auto *tempclass = recDecl->getDescribedClassTemplate();
if (tempclass) {
beginLoc = tempclass->getBeginLoc();
} else {
beginLoc = recDecl->getBeginLoc();
}
std::vector<FixItHint> fixits;
std::string message;
auto warningLocation = beginLoc;
SourceRange fixitRange = SourceRange(beginLoc, endLoc);
CharSourceRange controledFixitRange = CharSourceRange(fixitRange, false);
if (!m_including_qcontainerfwd) {
fixits.push_back(FixItHint::CreateReplacement(controledFixitRange, "#include <QtCore/qcontainerfwd.h>\n"));
} else {
fixits.push_back(FixItHint::CreateRemoval(controledFixitRange));
}
message += "Using forward declaration of ";
message += recDecl->getNameAsString();
message += ".";
if (m_including_qcontainerfwd) {
message += " (already)";
}
message += " Including <QtCore/qcontainerfwd.h> instead.";
emitWarning(warningLocation, message, fixits);
m_including_qcontainerfwd = true;
return;
}