Topic: Defect Report: implementation dependence and template parameters


Author: Richard Damon <rdamon@BeltronicsInspection.com>
Date: Thu, 6 Dec 2001 19:14:22 GMT
Raw View
Wouldn't you want that unsigned? if int(4294967291) -> -5 then overflow has
occurred, which I believe would result in undefined behavior. If the template
uses type unsigned then unsigned(-5) will go to some number, which is based on
the size of an unsigned. This may or may not be 4294967291.

Richard Damon

"Sergey P. Derevyago" <non-existent@iobox.com> wrote:

> [Moderator's note: this defect report has been
> forwarded to the C++ committee. -moderator.]
>
>Section: 1.3.14 [defns.well.formed], 14.1 [temp.param]
>Submitter: Sergey P. Derevyago
>
>It is not clear whether the following program is well-formed:
>-----------------------------------8<-----------------------------------
>template <int TI> struct A { };
>
>template<> struct A<4294967291> { };  // specialization 1
>template<> struct A<-5> { };          // specialization 2
>
>int main() { }
>-----------------------------------8<-----------------------------------
>Note that on some implementations int(4294967291)==-5 so the second
>specialization can collide with the first one. It seems like the code is a
>"partially well-formed program" but the standard doesn't address the issue in
>question.

--
richard_damon@iname.com (Redirector to my current best Mailbox)
rdamon@beltronicsInspection.com (Work Adddress)
Richad_Damon@msn.com (Just for Fun)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: iltchenko@yahoo.com (Andrei Iltchenko)
Date: Fri, 7 Dec 2001 17:44:39 GMT
Raw View
"Sergey P. Derevyago" <non-existent@iobox.com> wrote in message news:<3C0F49A3.4E733C4F@iobox.com>...

> It is not clear whether the following program is well-formed:
> -----------------------------------8<-----------------------------------
> template <int TI> struct A { };
>
> template<> struct A<4294967291> { };  // specialization 1
> template<> struct A<-5> { };          // specialization 2
>
> int main() { }
> -----------------------------------8<-----------------------------------

Whether or not the above program is well-formed depends on the
implementation-dependent characteristics of integral types. And the
standard is pretty clear about that.


> Note that on some implementations int(4294967291)==-5 so the second
> specialization can collide with the first one. It seems like the code is a
> "partially well-formed program" but the standard doesn't address the issue in
> question.

It is implementation-defined whether the program you wrote up violates
the ODR, i.e. the well-formedness of the program is
implementation-defined. Examples of such programs abound:

int  main()
{
   unsigned   i = 600000000000000000000000000000;
}

Once again your submission stands a good chance of ending up under the
"Not A Defect" status.


Regards,

Andrei Iltchenko.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Sergey P. Derevyago" <non-existent@iobox.com>
Date: 06 Dec 01 10:35:10 GMT
Raw View
 [Moderator's note: this defect report has been
 forwarded to the C++ committee. -moderator.]

Section: 1.3.14 [defns.well.formed], 14.1 [temp.param]
Submitter: Sergey P. Derevyago

It is not clear whether the following program is well-formed:
-----------------------------------8<-----------------------------------
template <int TI> struct A { };

template<> struct A<4294967291> { };  // specialization 1
template<> struct A<-5> { };          // specialization 2

int main() { }
-----------------------------------8<-----------------------------------
Note that on some implementations int(4294967291)==-5 so the second
specialization can collide with the first one. It seems like the code is a
"partially well-formed program" but the standard doesn't address the issue in
question.
--
         With all respect, Sergey.          http://cpp3.virtualave.net/
         mailto : ders at skeptik.net
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]