all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Yuri Khan <yuri.v.khan@gmail.com>
Cc: Oleh Krehel <oleh@oremacs.com>, Emacs developers <emacs-devel@gnu.org>
Subject: Re: CC-mode highlight change between 24.5 and 25
Date: Fri, 2 Sep 2016 14:40:55 +0000	[thread overview]
Message-ID: <20160902144055.GE4439@acm.fritz.box> (raw)
In-Reply-To: <CAP_d_8Uj3W+cqP-ezMJihmwrqpg2zWmzKsgUFQBTnYnBWdgU5g@mail.gmail.com>

Hello, Yuri.

On Fri, Sep 02, 2016 at 08:10:33PM +0600, Yuri Khan wrote:
> On Fri, Sep 2, 2016 at 8:27 PM, Alan Mackenzie <acm@muc.de> wrote:

> >> 4      std::ofstream fout (file_name);

> > The trouble is that L4 looks _exactly_ like a function declaration, the
> > function `fout' returning something of type `std::ofstream', and taking
> > a single parameter of type `file_name'.

> > Can you help me out here, please - by what criterion is the C++ compiler
> > deciding that `fout' is a variable initialised to `file_name' rather
> > than a function declaration?

> There is no such criterion in the syntax alone.

I feared as much.  I've often wondered why the C++ language developers
have had such a low regard for unambiguous syntax, such as most other
(computer) languages have.  I've cursed them for it on more than one
occasion.

> The more famous version of this ambiguity is called “C++’s most vexing
> parse”. Lifting an example from Scott Meyers, Effective STL, chapter 1
> Item 6:

>     list<int> data(istream_iterator<int>(dataFile),  // warning! this doesn't do
>                    istream_iterator<int>());         // what you think it does

> This looks like initialization of a variable “data” of type
> “list<int>” with a pair of iterators which are constructed on the
> spot, but it can alternatively be parsed as a declaration of a
> function named “data” that returns a list<int> and accepts two
> arguments, the first of which is named “dataFile” and has type
> “istream_iterator<int>”, and the second of which is unnamed and has
> type “function of no arguments returning istream_iterator<int>”.

> The C++ syntax requires the compiler to resolve the ambiguity in favor
> of a declaration.

> The canonical workaround is to add parentheses around arguments so
> that they no longer fit the syntax of a function argument:

>     list<int> data((istream_iterator<int>(dataFile)),
>                    istream_iterator<int>());

> In the original “fout” example, the ambiguity does not arise because
> the compiler knows “file_name” to be a value, not a type, and because
> there is no implicit int in C++.

In other words, only semantics determine that the line 4 is a variable
declaration rather than a function declaration.  CC Mode doesn't do
semantics, except to a _very_ limited degree.  So we're reduced, yet
again, to difficult and unreliable heuristics.  Curse the C++ language
developers!

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2016-09-02 14:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-02 11:58 CC-mode highlight change between 24.5 and 25 Oleh Krehel
2016-09-02 13:27 ` Alan Mackenzie
2016-09-02 14:10   ` Yuri Khan
2016-09-02 14:40     ` Alan Mackenzie [this message]
2016-09-02 17:39       ` Davis Herring
2016-09-02 17:48         ` Eli Zaretskii
2016-09-04 22:29         ` Alan Mackenzie
2016-09-02 14:18   ` Oleh Krehel
2016-09-02 14:31     ` Alan Mackenzie
2016-09-02 17:21       ` Davis Herring
2016-09-04 15:38     ` Alan Mackenzie
2016-09-05  9:27       ` Oleh Krehel
2016-09-05 15:20         ` Alan Mackenzie
2016-09-06 13:37           ` Oleh Krehel
2016-09-06 17:02             ` Alan Mackenzie
2016-09-07 14:10               ` Alan Mackenzie
2016-09-09 10:01                 ` Oleh Krehel
2016-09-11 21:22                   ` Alan Mackenzie

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=20160902144055.GE4439@acm.fritz.box \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=oleh@oremacs.com \
    --cc=yuri.v.khan@gmail.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.