From 1736a0234c6abe88019fbfaf49d8ae67c1f8f6ca Mon Sep 17 00:00:00 2001 From: Krzysztof Bieganski Date: Wed, 25 Oct 2023 16:43:14 +0200 Subject: [PATCH] Prevent static access to non-static class member Signed-off-by: Krzysztof Bieganski --- src/V3LinkDot.cpp | 12 +++++------- test_regress/t/t_class_member_bad3.pl | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 85f25faf94..83d6fca1ba 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2740,9 +2740,8 @@ class LinkDotResolveVisitor final : public VNVisitor { } } else { if (staticAccess && !varp->lifetime().isStatic() && !varp->isParam()) { - // TODO bug4077 - // nodep->v3error("Static access to non-static member variable " - // << varp->prettyNameQ() << endl); + nodep->v3error("Static access to non-static member variable " + << varp->prettyNameQ() << endl); } AstVarRef* const refp = new AstVarRef{ nodep->fileline(), varp, VAccess::READ}; // lvalue'ness computed later @@ -3187,10 +3186,9 @@ class LinkDotResolveVisitor final : public VNVisitor { AstNodeFTask* const taskp = foundp ? VN_CAST(foundp->nodep(), NodeFTask) : nullptr; // Maybe nullptr if (taskp) { - if (staticAccess && !taskp->isStatic()) { - // TODO bug4077 - // nodep->v3error("Static access to non-static task/function " - // << taskp->prettyNameQ() << endl); + if (staticAccess && taskp->classMethod() && !taskp->isStatic()) { + nodep->v3error("Static access to non-static task/function " + << taskp->prettyNameQ() << endl); } nodep->taskp(taskp); nodep->classOrPackagep(foundp->classOrPackagep()); diff --git a/test_regress/t/t_class_member_bad3.pl b/test_regress/t/t_class_member_bad3.pl index 55ca436afc..376c2d2eea 100755 --- a/test_regress/t/t_class_member_bad3.pl +++ b/test_regress/t/t_class_member_bad3.pl @@ -11,8 +11,8 @@ scenarios(linter => 1); lint( - # fails => 1, # TODO bug4077 - # expect_filename => $Self->{golden_filename}, + fails => 1, + expect_filename => $Self->{golden_filename}, ); ok(1);