Jump to content

Recommended Posts

I am using C++ Builder 11.  alignas does not see,m to fully implemented.  It is a C++11 feature so it isn't that new.  This code produces an error saying alignas cannot be applied to types.  It does seem to be valid code.

 

template <
    typename T
>
struct CreateStatic {
    static T* Create() {
        static char alignas(std::max_align_t) staticMemory_[sizeof(T)] ;
        return new (&staticMemory_) T;
    }

    static void Destroy(T* const p) {
        p->~T();
    }
};

 

Share this post


Link to post
Posted (edited)

Which compiler(s) is your project using?  alignas is supported only in the clang compilers, not in the classic compiler.

 

What is the EXACT error message, verbatim?

 

Also, FYI, you should be using alignas(T) instead. Or, since T is a template argument, use alignas(std::alignment_of<T>::value) or alignas(std::alignment_of_v<T>) instead.

Edited by Remy Lebeau

Share this post


Link to post

I don't use the classic compiler.  I can compile all of the unit this is in with the classic compiler and it has some code of C++11 and later.  I think you said somewhere it only supports C++03 but I am not seeing that.

 

The message is 'alaignas' attribute cannot be applied to types.  Taken literally that doesn't make sense.  An alias declaration can have it and they have types.

 

alignas(T) is an improvement to the original code.

Share this post


Link to post
Posted (edited)

I have installed a trial of C++ Builder 12.1.  The bug is still present with Clang 15.

Edited by Fraser
mistake

Share this post


Link to post
Posted (edited)
6 hours ago, Fraser said:

I can compile all of the unit this is in with the classic compiler and it has some code of C++11 and later.  I think you said somewhere it only supports C++03 but I am not seeing that.

The classic compiler is not a C++11 compiler, but it does have a handful of C++11 features implemented (but not alignas).

 

C++11 Features in the Classic Compiler

http://docwiki.embarcadero.com/RADStudio/en/C%2B%2B11_Features_in_the_Classic_Compiler

Edited by Remy Lebeau

Share this post


Link to post

That is the bug, thanks.  alignas does compile with the classic compiler so that list could be incomplete.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×