Topic: decltype on an object name with unknown type
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Mon, 11 Jan 2010 18:17:08 CST Raw View
Is the following code well-formed?
extern int a[];
decltype(a) b = { 1, 2, 3 };
"a" is an unparenthesized id-expression, for which n3000 says "decltype(e)
is the type of the entity named by e.". There is no more direct entity than
"object" or "variable" in this case, it seems (such as 'name'). But the type
of the object named isn't known.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Kaz Kylheku <kkylheku@gmail.com>
Date: Tue, 12 Jan 2010 01:08:33 CST Raw View
On 2010-01-12, Johannes Schaub (litb) <schaub-johannes@web.de> wrote:
> Is the following code well-formed?
>
> extern int a[];
> decltype(a) b = { 1, 2, 3 };
>
> "a" is an unparenthesized id-expression, for which n3000 says "decltype(e)
> is the type of the entity named by e.". There is no more direct entity
than
> "object" or "variable" in this case, it seems (such as 'name'). But the
type
> of the object named isn't known.
I don't see any deep problem here, given that the following
is valid 1990 ISO C:
typedef int incomplete_array_t[];
incomplete_array_t b = { 1, 2, 3 };
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Sean Hunt <rideau3@gmail.com>
Date: Tue, 12 Jan 2010 01:08:44 CST Raw View
On Jan 11, 5:17 pm, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
> Is the following code well-formed?
>
> extern int a[];
> decltype(a) b = { 1, 2, 3 };
>
> "a" is an unparenthesized id-expression, for which n3000 says "decltype(e)
> is the type of the entity named by e.". There is no more direct entity
than
> "object" or "variable" in this case, it seems (such as 'name'). But the
type
> of the object named isn't known.
a's type is 'array of unkown bound of int', which is an incomplete
type ([dcl.array]/1). Therefore the decltype indicates that type, and
this code is well-formed. b's type is 'array of 3
int' ([dcl.init.aggr]/4).
Sean
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Tue, 12 Jan 2010 03:44:03 CST Raw View
Sean Hunt wrote:
> On Jan 11, 5:17 pm, "Johannes Schaub (litb)" <schaub-johan...@web.de>
> wrote:
>> Is the following code well-formed?
>>
>> extern int a[];
>> decltype(a) b = { 1, 2, 3 };
>>
>> "a" is an unparenthesized id-expression, for which n3000 says
>> "decltype(e) is the type of the entity named by e.". There is no more
>> direct entity
> than
>> "object" or "variable" in this case, it seems (such as 'name'). But the
> type
>> of the object named isn't known.
>
> a's type is 'array of unkown bound of int', which is an incomplete
> type ([dcl.array]/1). Therefore the decltype indicates that type, and
> this code is well-formed. b's type is 'array of 3
> int' ([dcl.init.aggr]/4).
>
Is a's type needed, or the type of the object that's named? I can see 3
different categories here:
* declared type (this is what is written in the code).
* type associated with name (this includes any modifications of the declared
type, 7[dcl.dcl]p6)
* type of the entity named (1.8[intro.object]p1 for objects: objects,
references and functions can have types)
I thought that these are different things:
// declared type of "a" is "int[]".
void f(int a[]) { }
// declared type of "f" is "void(T)"
template<typename T> void f(T);
// type associated with "a" is "int*" (parameter type transformations)
// type of the entity named by "a" is "int*" likewise.
void g(int a[]);
// type associated with "f" is "void(T)"
// type of the entity named by "f" does not exist (templates don't have
types)
template<typename T> void f(T);
Sometimes the standard directly refers to the most lowlevel thing "declared
type". So it does in 18.10[support.runtime]p3, referring to a parameter
declared with array type.
An object introduced by a declaration is created by a definition and its
type with which it is created (1.8[intro.object]), but in my "int[]" example
with decltype above the definition hasn't shown up yet. We merely know the
type associated with the name 'a'.
Does the type of the object, in this case, change during compilation of the
TU from the first to the last declaration of it?
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]