c++c++11clangc++builderc++builder-10-seattle

Clang: Binding of reference to a value of type 'const TClass' drops qualifiers


I have the following method which compiles fine using the "classic" bcc32 compiler, but fails to compile using the Rad Studio 10 Clang compiler.

TPersistentClass & __fastcall TService_REST_Server_Ol::OnServerMethods()
{
    return __classid(TServerMethods_RSO);
}

The compiler produces the following error:

[CLANG Error] Service_REST_Server_OlU.cpp(37): binding of reference to type 'TPersistentClass' (aka 'System::TMetaClass *') to a value of type 'const TClass' (aka 'System::TMetaClass *const') drops qualifiers

If I understand correctly, based on this question, the reason this does not work is because the code is attempting to return a non-const reference to a const object. However, I am unsure syntactically how I go about solving this issue. Is there a way to indicate in the method definition that I want to return a const?


Solution

  • If you want to return a const reference you must declare it.

    const TPersistentClass & __fastcall TService_REST_Server_Ol::OnServerMethods()
    {
        return __classid(TServerMethods_RSO);
    }