public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gareth McCaughan <gmccaughan@synaptics-uk.com>
To: Ivan Molella <i.molella@reply.it>
Cc: gcc@gcc.gnu.org
Subject: Re: compiler confusion?
Date: Thu, 24 Apr 2003 15:12:00 -0000	[thread overview]
Message-ID: <200304241411.01100.gmccaughan@synaptics-uk.com> (raw)

Here's a stripped-down version of your code that exhibits
the same problem.

    struct A {
      A(bool x) {}
    };
    
    struct C {
      void f();
    };
    
    static int g() { return 1; }
    void C::f() {
      A(g() == 100);
    }

Here's what I think is going on: the compiler is seeing
that line "A(g() == 100);" as a declaration of a function
called g, returning a value of type A. The same as if it said
"A g() == 100;". And, of course, when it gets to the "==",
that stops making any sense :-).

I'm not enough of a C++ standards guru to know whether
this behaviour is (1) allowed and/or (2) required. It's
weird, certainly, but there are other almost equally
ludicrous interpretations that *are* required by the
standard. For instance, here's an example from Scott Meyers's
"Effective STL".

    ifstream dataFile("ints.dat");
    list<int> data(istream_iterator<int>(dataFile),
                   istream_iterator<int>());

Perhaps contrary to appearances, what this does is
to declare a function called "data" taking two
arguments: the first is of type istream_iterator<int>
and is named "dataFile", and the second is of type
"pointer to function from void to istream_iterator<int>"
and has no name. :-)

-- 
g



             reply	other threads:[~2003-04-24 13:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-24 15:12 Gareth McCaughan [this message]
2003-04-25  9:00 ` wilson k.j
  -- strict thread matches above, loose matches on Subject: below --
2003-04-23 16:03 Ivan Molella
2003-04-23 15:46 Ivan Molella
2003-04-23 13:29 Ivan Molella

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=200304241411.01100.gmccaughan@synaptics-uk.com \
    --to=gmccaughan@synaptics-uk.com \
    --cc=gcc@gcc.gnu.org \
    --cc=i.molella@reply.it \
    /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).