Leont/libperl--

typecast_to is broken for C types. t/40-typecasts.C fails.

Closed this issue · 3 comments

int foo = typecast_to(scalar);
is(foo, 1, "foo == 1");

This fails at run time in the 40-typecasts.C test. The cast function returns zero. I confirmed it also fails for other built in types including double and float.

The template specialization included below fixes specifically the "int" failure. My template fu is too weak to dive into interpreter.h.

=== modified file 't/40-typecasts.C'
--- t/40-typecasts.C 2011-04-28 01:57:56 +0000
+++ t/40-typecasts.C 2011-04-29 02:49:34 +0000
@@ -23,6 +23,15 @@
return variable.value;
}
};
+

  •   template<> struct typemap<int> {
    
  •       static int cast_to(const Scalar::Base& value) {
    
  •           return value.int_value();
    
  •       }
    
  •       static int cast_from(Interpreter&, const int variable) {
    
  •           return variable;
    
  •       }
    
  •   };
    
    }
    }

It seems to be an issue on gcc 4.5 and up, 4.4 works just fine. When building t/40-typecasts.C it emits a warning on exactly that line: «warning: '' may be used uninitialized in this function». I'm not quite understanding what's going on though.

I've figured out where the error happens. Fixing this may require substantial rewriting of the typemapping tough, unless C++0X is letting me get away with this in another way.

I've just pushed a fix to repo. It seems gcc's handling of C++0X changed in a subtle way. I think I understand why they did it, but that took some meditation.