Home > Archive > VC Language > March 2005 > VC71 bug: static call through object
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
VC71 bug: static call through object
|
|
| Michiel Salters 2005-03-30, 9:03 am |
| >-----Original Message-----
>Hi to all
>
>VC71 has some problems _running_ the following console
program, when
>"left" and "right" are declared static in binary_tree<T>
>
>
>int main(int argc, char* argv[])
>{
> binary_tree<double> tr;
>
> tr.push_back(0);
> tr.push_back(0, 3.14, tr.left() );
> tr.push_back(1, 6.28, tr.right() );
>
> return 0;
>}
>
>
>note that here the problem is only about syntactic sugar:
>basically tr.left() does nothing, only the return type
matters, so
>declaring it static or const has no practical meaning.
Actually, it does. Not only do you call the function,
but you also use a pointer to member pointing to that
function.
>
>to reproduce the bug, change the #if 0 below to
> #if 1 and run the program.
>maybe the example can be stripped off even more,
> but this is part of a much larger source.
Please do so, posting an excessive sample is the
most common reason for no replies. You certainly
didn't need 'right' if 'left' crashed earlier.
>#include <vector>
>#include <cassert>
>
>
>template <typename T, typename S, S T::*pointer>
>struct member_t
>{
> S& operator()(T& x) const
> {
> return x.*pointer;
> }
>};
Note that pointer must be a pointer-to-member.
>
>template <typename scalar_t>
>class binary_tree
>{
>public:
> typedef size_t position_t;
>
>private:
> struct node_t
> {
> position_t left;
>
> node_t( const scalar_t& x )
> : left(npos()){ }
> static position_t npos() {
> return -1;
> }
> };
>
> std::vector< node_t > tree_;
>
>public:
>
> typedef member_t< node_t,position_t, &node_t::left >
left_t;
I'm not sure how this can compile. First, node_t::left
is not in scope, and secondly, if it was, it wouldn't
be a pointer to member (because in your example, it's
static and the address of a static member is a plain
function pointer).
>
>#if 0
>
>#define STATIC
>#define CONST const
>
>#else
>
>#define STATIC static
>#define CONST
>
>#endif
>
> STATIC left_t left() CONST
> {
> return left_t();
> }
> template <typename branch_t>
> position_t push_back(const position_t id,
> const scalar_t& x, const branch_t branch);
>};
I do think VC71 has a bug, the type error should be
detected at compile time. Still, the most important
bug is in your code.
Regards,
Michiel Salters
| |
| Mycroft Holmes 2005-03-30, 4:02 pm |
| In article <044801c5351e$fdf72250$a401280a@phx.gbl>,
"Michiel Salters" <msalters@discussions.microsoft.com> wrote:
>
> Actually, it does. Not only do you call the function,
> but you also use a pointer to member pointing to that
> function.
>
???
possibly I was not clear enough: I said that it has no impact on my code
to declare 'left' static or const, because even if in theory it should
be static, in practice you'll call it through the object you have.
> Please do so, posting an excessive sample is the
> most common reason for no replies. You certainly
> didn't need 'right' if 'left' crashed earlier.
I think we could argue on the meaning of "excessive".
However I strictly doubt a 1-line method can be defined "excessive",
especially since it helps clarifying the purpose of the code.
I'm only stating that this sample shows the bug, I don't know if it's
minimal but it's so small anyway that Microsoft servers won't overheat
transmitting it :)
>
> Note that pointer must be a pointer-to-member.
???
and what type do you think "pointer" is, btw?
> I do think VC71 has a bug, the type error should be
> detected at compile time. Still, the most important
> bug is in your code.
>
I think you didn't read my message with sufficient attention.
please, if you have time, do so before posting misleading replies.
btw, the code is completely correct and strictly standard conforming.
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
|
|
|
|
|