Funny object declarations

47 views
Skip to first unread message

Johannes Schaub

unread,
Jun 19, 2015, 4:35:39 AM6/19/15
to std-dis...@isocpp.org

Hello all,

The spec still says at 7p7 "If the decl-specifier-seq contains no typedef specifier, the declaration is called a function declaration if the
type associated with the name is a function type (8.3.5) and an object declaration otherwise."

That is defective and must be fixed because it ignores the fact that the type can be a reference type. Perhaps it can also use a footnote, because "T t" (with a template parameter) may change from being an object declaration to being a reference declaration when the template is instantiated.

dyp

unread,
Jun 19, 2015, 5:50:24 AM6/19/15
to std-dis...@isocpp.org
Let's look at the usages of _object-declaration_:

(numbers are taken from C++14 IS, but no additional occurrences in
recent drafts)

7p8 An object declaration, however, is also a definition unless it
contains the extern specifier and has no initializer

Also applies to references.

7.1.5p9 A constexpr specifier used in an object declaration declares the
object as const. Such an object [...]

Only applies to objects.

8.2p1 The ambiguity arising from the similarity between a function-style
cast and a declaration mentioned in 6.8 can also occur in the context of
a declaration. In that context, the choice is between a function
declaration with a redundant set of parentheses around a parameter name
and an object declaration with a function-style cast as the initializer.

Applies to both, but to me seems to be more informative than normative.

C.1.6 For ease of use, C ++ doesn’t require that a type name be prefixed
with the keywords class, struct or union when used in object
declarations or type casts.

Irrelevant / applies to both. Informative IMHO


Can't find any relevant issues on the CWG lists.

I remember having wondered about that definition myself some time ago,
but I just suspected this to be another lax usage of words
(differentiate function declarations from object+reference
declarations). 7.1.5p9 however doesn't seem to be correct wrt object
declarations of references.


Kind regards,

dyp





On 19.06.2015 10:35, 'Johannes Schaub' via ISO C++ Standard - Discussion
wrote:
Reply all
Reply to author
Forward
0 new messages