Topic: is_volatile<T> gives wrong answer for references and functions


Author: notbob@tessellation.com (Robert Allan Schwartz)
Date: Fri, 9 May 2003 00:19:14 +0000 (UTC)
Raw View
===================================== MODERATOR'S COMMENT:
 Please don't overquote.


===================================== END OF MODERATOR'S COMMENT
google@dalvander.com (Anders Dalvander) wrote in message news:<d04c84a9.0305080931.609ce9a2@posting.google.com>...
> Take a look at http://www.boost.org/libs/type_traits/index.htm (Boost
> - Type Traits), and see how they have solved it.
>
> ---
> [ 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.jamesd.demon.co.uk/csc/faq.html                       ]

I did, but I still want to know why my way of doing it doesn't get the
results I expected.

Robert

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: google@vandevoorde.com (Daveed Vandevoorde)
Date: Fri, 9 May 2003 17:20:51 +0000 (UTC)
Raw View
notbob@tessellation.com (Robert Allan Schwartz) wrote:
[...]
> I did, but I still want to know why my way of doing it doesn't get the
> results I expected.

I think it's a GNU C++ 3.2 bug.  At least on MacOS X,
it gives suspicious warnings about ignoring the
volatile qualifiers while instantiating is_volatile
(apparently, it finds the partial specialization an
acceptable match).

        Daveed

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: cpdaniel@nospam.mvps.org ("Carl Daniel")
Date: Fri, 9 May 2003 17:21:33 +0000 (UTC)
Raw View
Robert Allan Schwartz wrote:
> google@dalvander.com (Anders Dalvander) wrote in message
>> Take a look at http://www.boost.org/libs/type_traits/index.htm (Boost
>> - Type Traits), and see how they have solved it.
>
> I did, but I still want to know why my way of doing it doesn't get the
> results I expected.

Most likely, for the same reason your is_const didn't work as expected:
compiler bugs.  The developers of boost:type_traits have spent a great deal
of time finding techniques that work on a wide variety of compilers.  That
may involve using a more complex yet still standard-conforming construct
(which the compilers happen to translate correctly), or it may involve
illegal constructs (which the compilers happen to translate into code with
the desired meaning despite it's being illegal).  (Caveat:  I haven't
studied boost:type_traits, so I don't know if any technically illegal code
is used - it's only supposition on my part that it might be the case).

-cd



---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: notbob@tessellation.com (Robert Allan Schwartz)
Date: Thu, 8 May 2003 03:53:33 +0000 (UTC)
Raw View
The program:

template <typename T>
class is_volatile { public: static const bool value = false; };

template <typename T>
class is_volatile<volatile T> { public: static const bool value = true; };

#include <iostream>

int main()
{
 std::cout << "is_volatile<bool &>::value = " << is_volatile<bool &>::value
<< std::endl;

 std::cout << "is_volatile<void (void)>::value = " << is_volatile<void
(void)>::value << std::endl;
 std::cout << "is_volatile<int  (void)>::value = " << is_volatile<int
(void)>::value << std::endl;
 std::cout << "is_volatile<int  (int )>::value = " << is_volatile<int  (int
)>::value << std::endl;

 return 0;
}

gives the results:

is_volatile<bool &>::value = 1
is_volatile<void (void)>::value = 1
is_volatile<int  (void)>::value = 1
is_volatile<int  (int )>::value = 1

on g++ v3.2, but gives the results:

is_volatile<bool &>::value = 0
is_volatile<void (void)>::value = 0
is_volatile<int  (void)>::value = 0
is_volatile<int  (int )>::value = 0

on metrowerks v7.

I believe the answers should all be 0.

What does the standard say?

Thank you,

Robert Schwartz

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: google@dalvander.com (Anders Dalvander)
Date: Thu, 8 May 2003 18:57:55 +0000 (UTC)
Raw View
Take a look at http://www.boost.org/libs/type_traits/index.htm (Boost
- Type Traits), and see how they have solved it.

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]