Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Explicit Type Conversion and Simple Type Specifiers

48 views
Skip to first unread message

James McNellis

unread,
Jan 29, 2010, 6:47:37 PM1/29/10
to
According to C++03 (5.2.3/2, expr.type.conv):

"The expression T(), where T is a simple-type-specifier (7.1.5.2) for
a non-array complete object type or the (possibly cv-qualified) void
type, creates an rvalue of the specified type, which is value-
initialized"

So, "int()" creates a value-initialized int rvalue. My question is
whether "unsigned int()" is well-formed.

Microsoft Visual C++ 2008 and Intel C++ 11.1 both accept "unsigned int
()" without any warnings; Comeau 4.3.10.1b2 and g++ 4.1.2 do not.

(7.1.5.2, dcl.type.simple) says "the simple type specifiers are," and
follows with a list that includes "unsigned" and "int". It is my
interpretation that "unsigned int" is thus a sequence (to use the
language of 3.9.1, note 40) or combination (to use the langauge of
7.1.5.2/1) of simple type specifiers, and is not itself a simple type
specifier.

If so, given that in 5.2.3/2, "simple-type-specifier" is singular and
"unsigned" and "int" are two type specifiers, it is my understanding
that "unsigned int()" is not well-formed.

I first asked the question on StackOverflow (http://stackoverflow.com/
questions/2144012/), and there was some discussion as to whether
"unsigned int" might in fact be a simple-type-specifier (especially
given 7.1.5.2/1, Table 7, captioned "simple-type-specifiers and the
types they specify"), and it's quite possible that I am
misinterpreting the standard.

Thank you,

James McNellis

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Daniel Krügler

unread,
Feb 1, 2010, 12:32:39 AM2/1/10
to
On 30 Jan., 00:47, James McNellis <ja...@jamesmcnellis.com> wrote:
> According to C++03 (5.2.3/2, expr.type.conv):
>
> "The expression T(), where T is a simple-type-specifier (7.1.5.2) for
> a non-array complete object type or the (possibly cv-qualified) void
> type, creates an rvalue of the specified type, which is value-
> initialized"
>
> So, "int()" creates a value-initialized int rvalue. My question is
> whether "unsigned int()" is well-formed.

No.

> Microsoft Visual C++ 2008 and Intel C++ 11.1 both accept "unsigned int
> ()" without any warnings; Comeau 4.3.10.1b2 and g++ 4.1.2 do not.
>
> (7.1.5.2, dcl.type.simple) says "the simple type specifiers are," and
> follows with a list that includes "unsigned" and "int". It is my
> interpretation that "unsigned int" is thus a sequence (to use the
> language of 3.9.1, note 40) or combination (to use the langauge of
> 7.1.5.2/1) of simple type specifiers, and is not itself a simple type
> specifier.

I agree with that interpretation.

> If so, given that in 5.2.3/2, "simple-type-specifier" is singular and
> "unsigned" and "int" are two type specifiers, it is my understanding
> that "unsigned int()" is not well-formed.

So is mine.

> I first asked the question on StackOverflow (http://stackoverflow.com/
> questions/2144012/), and there was some discussion as to whether
> "unsigned int" might in fact be a simple-type-specifier (especially
> given 7.1.5.2/1, Table 7, captioned "simple-type-specifiers and the
> types they specify"), and it's quite possible that I am
> misinterpreting the standard.

I agree that the header of Table 7 (which is Table 9 in the most
recent draft N3000) is somewhat misleading, but the preceeding
text in [dcl.type.simple]/2 looks very clear to me, when it says:

"Table 7 summarizes the valid combinations of simple-type-specifiers
and the types they specify."

HTH & Greetings from Bremen,

Daniel Kr�gler

0 new messages