public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52032] New: Function and class attributes should optionally take a bool parameter enabling them
@ 2012-01-28 23:46 joseph.h.garvin at gmail dot com
  2012-01-30 10:06 ` [Bug c++/52032] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: joseph.h.garvin at gmail dot com @ 2012-01-28 23:46 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-30 21:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-28 23:46 [Bug c++/52032] New: Function and class attributes should optionally take a bool parameter enabling them joseph.h.garvin at gmail dot com
2012-01-30 10:06 ` [Bug c++/52032] " rguenth at gcc dot gnu.org
2012-01-30 13:43 ` joseph.h.garvin at gmail dot com
2012-01-30 13:47 ` rguenth at gcc dot gnu.org
2012-01-30 21:39 ` joseph.h.garvin at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).