How to suppress warning W7041 in BCC64?

In a Borland C++Builder non-modern 64bit codebase (bcc64) that I’m working on, a number of class definitions emit the following warning:

warning W7041: Interface ‘XXX’ does not derive from IUnknown. (Interfaces should derive from IUnknown)

This typically happens in VCL projects (Delphi-style). Minimal example:

class Base
{
public:
    Base();
    virtual ~Base();

    virtual void interface_method() = 0;
    virtual void concrete();
};

class TMyForm : public TForm, public Base
{
__published:
private:
public:
    __fastcall TMyForm(TComponent* Owner);

    void interface_method(); // override
};

The unit compiles and links, but emits the above warning. So far I haven’t experienced any runtime issues, so I assume it does not cause any trouble.

Main concern: Suppress the warning

Rather than interfere with the class hierarchy, I would like to suppress the warning.

I have tried:

  • Compiler options UI – warning is not featured there
  • #pragma diagnostic ignored "-Wall" (Clang)
  • #pragma warn disable (bcc32 only)

But the warning still appears. I suspect that this warning is probably a language extension specific to the Borland frameworks. Therefore, the standard compiler mechanisms might not work.

Delphi/VCL conventions

One piece of additional information related to this issue: If class Base does not have any pure virtual methods, compilation fails, as in the following, modified example:

class Base
{
public:
    Base();
    virtual ~Base();
};

class TMyForm : public TForm, public Base
{
__published:
private:
public:
    __fastcall TMyForm(TComponent* Owner);
};

This time, the compiler issues the following error:

[bcc64 Error] test.h(21): Delphi style classes have to be derived from Delphi style classes

6

While I haven’t found a solution that works without touching the class hierarchy, and couldn’t silence the warning either, here is one solution that has minimal impact.

Background:
The article Inheritance and interfaces | C++ and Delphi Class Models covers the relevant Delphi/VCL and COM conventions for multiple (or interface) inheritance and describes possible strategies for implementing the IUnknown interface.

Applied to the minimal example, the solution would look like this:

class Base : public IUnknown
{
public:
    virtual ~Base();
    virtual void abstract_method() = 0;
};

class TMyForm : public TForm, public Base
{
    INTFOBJECT_IMPL_IUNKNOWN(TComponent);

__published:
private:
public:
    __fastcall TMyForm(TComponent* Owner) override;

    void abstract_method() override;
};

The macro INTFOBJECT_IMPL_IUNKNOWN will take care of implementing IUnknown using methods present in TComponent.

If you need to inherit from Base in a class that is not derived from TComponent, you can derive that class can from TInterfacedObject instead:

class CustomClass : public TInterfacedObject, public Base
{
    INTFOBJECT_IMPL_IUNKNOWN(TInterfacedObject);

public:
    void abstract_method() override;
};

If you cannot change your custom class to inherit from TInterfacedObject or TComponent, the only choice left is to manually implement IUnknown. (See the above-mentioned article.)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật