This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52032] New: Function and class attributes should optionally take a bool parameter enabling them
- From: "joseph.h.garvin at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 28 Jan 2012 23:17:00 +0000
- Subject: [Bug c++/52032] New: Function and class attributes should optionally take a bool parameter enabling them
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52032
Bug #: 52032
Summary: Function and class attributes should optionally take a
bool parameter enabling them
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: joseph.h.garvin@gmail.com
Summary: Attributes like packed, always_inline, etc. should support taking a
bool to enable them, similar to how 'noexcept' works in C++11.
Details:
In C++11, one can add the 'noexcept' specifier on to a function to indicate
that it doesn't throw exceptions, e.g.:
void foo() noexcept
{
// ...
}
However, to assist with template metaprogramming, noexcept can take compile
time constant bool to switch whether it's in effect:
struct MyCallback
{
};
template<class CallbackT>
void foo() noexcept(!CallbackT::ThrowsExceptions)
{
CallbackT::action();
}
It would reduce redundant code if GCC let you do this in general for its
attributes. For example, currently if you want both a packed and unpacked
version of a struct, you are forced to either define the struct twice or
generate both versions with a macro. Ideally you could do this:
template<bool should_pack=false>
struct __attribute__((__packed__(should_pack))) MyStruct
{
// ... members
}
typedef MyStruct<true> PackedMyStruct;
This functionality could be useful for pretty much all of GCC's attributes.