From: Michael Welsh Duggan <mwd@md5i.com>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: Help sought from C++ expert: is this `value' a type or something else (what)?
Date: Thu, 19 Jan 2023 10:41:15 -0500 [thread overview]
Message-ID: <87pmbav8f8.fsf@md5i.com> (raw)
In-Reply-To: <Y8lZYoDmlzEmKLra@ACM> (Alan Mackenzie's message of "Thu, 19 Jan 2023 14:53:22 +0000")
Alan Mackenzie <acm@muc.de> writes:
> In the following test file, templates-9.cc from the CC Mode test suite,
> on the indicated line, what is the syntactic significance of `value'?
Here `value' is a value, specifically a boolean struct member. This is
boost's implementation of what became, in C++11, `std::is_same', which
can be found documented here:
https://en.cppreference.com/w/cpp/types/is_same
> Traditionally, it has fontified with the default face, but recently after
> some (not yet committed) changes in CC Mode, it has started getting
> font-lock-type-face.
>
> I don't understand the file at all, hardly, and can't work out whether
> the old (non-) fontification was correct, or whether the new
> fontification of f-l-type-face is correct. Help would be appreciated.
Given a name `Foo', the compiler doesn't necessarily know if `Foo::bar'
is a type or a value, because it doesn't necessarily know what type Foo
is - it could be a template argument, for example, and won't be known
until an instance is referenced. The assumption is that it is a value.
If it was a type, this is pointed out to the compiler by calling it
`typename Foo::bar'. For more on this, see:
https://en.cppreference.com/w/cpp/language/dependent_name
From that page, "In a declaration or a definition of a template,
including alias templates, a name that is not a member of the current
instantiation and is dependent on a template parameter is not considered
to be a type unless the keyword `typename' is used or unless it was
already established as a type name, e.g. with a typedef declaration or
by being used to name a base class."
> Just as a matter of interest, in c++-ts-mode a treesit-query-error gets
> thrown. It isn't clear to me whether the file is still valid C++.
It looks valid. The `template' before the `then' is, like `typename' a
disambiguator for the dependent name `then', stating that it is a
template name.
> /////////////////////////////////////////////////////////////////////////
> typedef std::pair<int
> , std::pair<long
> , std::pair<char*
> , std::pair<nil,nil>
> >
> >
> > list_of_types;
>
> typedef std::pair<
> int, std::pair<
> long, std::pair<
> char*, std::pair<nil,nil>
> >
> >
>> list_of_types;
>
> typedef typename if_true
> <
> boost::is_same
> <
> boost::add_pointer<X>
> , int*
> >::value // <===================================================
>>::template then
> <
> boost::remove_reference<X>
> // else
> , X
>>::type modified_X;
> /////////////////////////////////////////////////////////////////////////
>
> Thanks!
--
Michael Welsh Duggan
(md5i@md5i.com)
next prev parent reply other threads:[~2023-01-19 15:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 14:53 Help sought from C++ expert: is this `value' a type or something else (what)? Alan Mackenzie
2023-01-19 14:59 ` Eli Zaretskii
2023-01-19 17:14 ` Difficulty building tree-sitter grammars [was: Help sought from C++ expert: ....] Alan Mackenzie
2023-01-19 17:53 ` Dmitry Gutov
2023-01-19 18:06 ` Eli Zaretskii
2023-01-19 18:16 ` Dmitry Gutov
2023-01-19 17:53 ` Eli Zaretskii
2023-01-19 20:56 ` Alan Mackenzie
2023-01-20 6:44 ` Eli Zaretskii
2023-01-19 15:41 ` Michael Welsh Duggan [this message]
2023-01-21 14:34 ` Help sought from C++ expert: is this `value' a type or something else (what)? Alan Mackenzie
2023-01-19 16:22 ` Óscar Fuentes
2023-01-21 14:59 ` 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pmbav8f8.fsf@md5i.com \
--to=mwd@md5i.com \
--cc=acm@muc.de \
--cc=emacs-devel@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).