Fraser 2 Posted June 6 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
Remy Lebeau 1393 Posted June 6 (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 June 6 by Remy Lebeau Share this post Link to post
Fraser 2 Posted June 7 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
Fraser 2 Posted June 7 (edited) I have installed a trial of C++ Builder 12.1. The bug is still present with Clang 15. Edited June 7 by Fraser mistake Share this post Link to post
Remy Lebeau 1393 Posted June 7 (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 June 7 by Remy Lebeau Share this post Link to post
Remy Lebeau 1393 Posted June 7 (edited) alignas attribute not recognized in specifier-qualifier position of a member declaration https://github.com/llvm/llvm-project/issues/81472 Edited June 7 by Remy Lebeau Share this post Link to post
Fraser 2 Posted June 7 That is the bug, thanks. alignas does compile with the classic compiler so that list could be incomplete. Share this post Link to post