public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: "John S. Fine" <johnsfine@verizon.net>
Cc: GCC Help Mailing List <gcc-help@gcc.gnu.org>
Subject: Re: Anonymous struct
Date: Wed, 07 Apr 2010 15:46:00 -0000	[thread overview]
Message-ID: <mcrmxxffep4.fsf@dhcp-172-17-9-151.mtv.corp.google.com> (raw)
In-Reply-To: <4BBC94A9.1020209@verizon.net> (John S. Fine's message of "Wed\, 07 Apr 2010 10\:20\:25 -0400")

"John S. Fine" <johnsfine@verizon.net> writes:

> Can someone with a good understanding of the C++ standard tell me if
> this program is legal C++
>
> #include <iostream>
> int x = 1;
> int main(int argc, char** argv)
> {
>    struct {
>        int operator()( int y ) { return x + y; }
>    } fun;
>
>    std::cout << fun( 7 ) << std::endl;
>    return 0;
> }
>
> It compiles and runs with gcc 4.4.1.  I have done similar things in
> other situations many times, so I assumed that it was valid.
>
> But another compiler (not a version of GCC) reports:
>
> error C2627: member function defined in unnamed class
>
> I hope that other compiler is just wrong.  But I'd like someone with a
> better understanding of the standard to comment.

You are not permitted to define a member function in an anonymous
union, but I don't see any such restriction for an anonymous class or
struct.

Ian

      reply	other threads:[~2010-04-07 15:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-07 14:20 John S. Fine
2010-04-07 15:46 ` Ian Lance Taylor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mcrmxxffep4.fsf@dhcp-172-17-9-151.mtv.corp.google.com \
    --to=iant@google.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=johnsfine@verizon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).