Workaround for C++0x Attributes (Clang-based C++ Compilers)

From Appmethod Topics
Jump to: navigation, search

Go Up to C++0x Features Index


The C++0x attributes deprecated, final (C++), and noreturn are not supported by Clang-based C++ compilers.

This page describes how to work around the missing deprecated and final (C++) attributes when using the 64-bit C++ compiler. There is no workaround for the noreturn attribute.

Workaround for the deprecated attribute

You can use #pragma obsolete as a workaround for the deprecated attribute. The following is a short example of code for a deprecated function.

In BCC32:

int f(int a)[[deprecated]]{
        //code here
}

In Clang-based C++ compilers:

int f(int a){
        #pragma obsolete f
        //code here
}

Workaround for the final attribute

In Clang-based C++ compilers, the final keyword is introduced, providing the same functionality as the C++0x final (C++) attribute.

The following is a short example of using the final keyword.

In BCC32:

class A {
        virtual int f()[[final]];
};

class B : public A {
        int f(); // error, 'f' is marked 'final' and cannot be overridden
};

In Clang-based C++ compilers:

class A {
        virtual int f() final;
};

class B : public A {
        int f(); //error, declaration of 'f' overrides 'final' function
};

See Also