Internal: Fix clang override warning (#7106 repair).

This commit is contained in:
Wilson Snyder 2026-02-19 21:34:17 -05:00
parent 0d2fcfd49d
commit ace9a34c10
6 changed files with 7 additions and 14 deletions

View File

@ -488,7 +488,6 @@ class AstCFunc final : public AstNode {
// an explicitly passed 'self' pointer as the first argument. This can
// be slightly faster due to __restrict, and we do not declare in header
// so adding/removing loose functions doesn't recompile everything.
bool m_isOverride : 1; // Override virtual function
bool m_isVirtual : 1; // Virtual function
bool m_entryPoint : 1; // User may call into this top level function
bool m_dpiPure : 1; // Pure DPI function
@ -520,7 +519,6 @@ public:
m_isDestructor = false;
m_isMethod = true;
m_isLoose = false;
m_isOverride = false;
m_isVirtual = false;
m_needProcess = false;
m_entryPoint = false;
@ -584,11 +582,6 @@ public:
bool isLoose() const { return m_isLoose; }
void isLoose(bool flag) { m_isLoose = flag; }
bool isProperMethod() const { return isMethod() && !isLoose(); }
bool isOverride() const { return m_isOverride; }
void isOverride(bool flag) {
m_isOverride = flag;
if (flag) isVirtual(true);
}
bool isVirtual() const { return m_isVirtual; }
void isVirtual(bool flag) { m_isVirtual = flag; }
bool needProcess() const { return m_needProcess; }

View File

@ -3233,7 +3233,6 @@ void AstCFunc::dump(std::ostream& str) const {
if (isDestructor()) str << " [DTOR]";
if (isMethod()) str << " [METHOD]";
if (isLoose()) str << " [LOOSE]";
if (isOverride()) str << " [OVERRIDE]";
if (isVirtual()) str << " [VIRT]";
if (isCoroutine()) str << " [CORO]";
if (needProcess()) str << " [NPRC]";
@ -3250,7 +3249,6 @@ void AstCFunc::dumpJson(std::ostream& str) const {
dumpJsonBoolFuncIf(str, dpiContext);
dumpJsonBoolFuncIf(str, isConstructor);
dumpJsonBoolFuncIf(str, isDestructor);
dumpJsonBoolFuncIf(str, isOverride);
dumpJsonBoolFuncIf(str, isVirtual);
dumpJsonBoolFuncIf(str, isCoroutine);
dumpJsonBoolFuncIf(str, needProcess);

View File

@ -94,7 +94,7 @@ static void makeToString(AstClass* nodep) {
AstCFunc* const funcp = new AstCFunc{nodep->fileline(), "to_string", nullptr, "std::string"};
funcp->isConst(true);
funcp->isStatic(false);
funcp->isOverride(true);
funcp->isVirtual(true);
funcp->protect(false);
AstCExpr* const exprp = new AstCExpr{nodep->fileline(), R"("'{"s + to_string_middle() + "}")"};
exprp->dtypeSetString();

View File

@ -153,10 +153,11 @@ void EmitCBaseVisitorConst::emitCFuncDecl(const AstCFunc* funcp, const AstNodeMo
if (funcp->isStatic() && funcp->isProperMethod()) putns(funcp, "static ");
if (funcp->isVirtual()) {
UASSERT_OBJ(funcp->isProperMethod(), funcp, "Virtual function is not a proper method");
if (!funcp->isOverride()) putns(funcp, "virtual ");
putns(funcp, "virtual ");
// Intentionally no emit for "override" instead, as clang will then enable warning
// on other methods where virtual vs override is needed, and this is not tracked yet
}
emitCFuncHeader(funcp, modp, /* withScope: */ false);
if (funcp->isOverride()) putns(funcp, " override");
if (funcp->emptyBody() && !funcp->isLoose() && !cLinkage) {
putns(funcp, " {}\n");
} else {

View File

@ -187,7 +187,8 @@ class EmitCHeader final : public EmitCConstInit {
decorateFirst(first, section);
const std::string name = V3OutFormatter::quoteNameControls(
VIdProtect::protectWordsIf(modp->prettyName(), v3Global.opt.protectIds()));
puts("const char* typeName() const override { return \""s + name + "\"; }\n");
// "override", but don't want clang to start checking them:
puts("virtual const char* typeName() const { return \""s + name + "\"; }\n");
}
if (v3Global.opt.coverage() && !VN_IS(modp, Class)) {

View File

@ -62,7 +62,7 @@ for filename in sorted(files.keys()):
contents = test.file_contents(filename) + "\n\n"
check_pattern(filename, contents, r"[^\']*virtual[^{};\n]+override[^\n]*", None,
check_pattern(filename, contents, r"[^\'/]*virtual[^{};\n]+override[^\n]*", None,
"'virtual' keyword is redundant on 'override' method")
check_pattern(filename, contents,