Explicit Type Conversion and Simple Type Specifiers

  • Follow


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! ]

0
Reply james167 (1) 1/29/2010 5:47:37 PM

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


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

0
Reply ISO 1/31/2010 11:32:39 PM


1 Replies
137 Views

(page loaded in 0.099 seconds)

Similiar Articles:













7/22/2012 2:35:19 PM


Reply: