These are chat archives for ChaiScript/ChaiScript

2nd
Aug 2015
Andreas Reischuck
@arBmind
Aug 02 2015 21:04
Hi, I am planning to give a ChaiScript introduction to our local C++ meetup next month
chaiscript\include\chaiscript\dispatchkit\boxed_cast.hpp(88) : warning C4172: returning address of local variable or temporary
MSVC2015 gives these warnings
Andreas Reischuck
@arBmind
Aug 02 2015 21:11
Cast_Helper_Inner supports to cast to a reference. But if the boxed_value is only a temporary, this will lead to issues or does it not?
Jason Turner
@lefticus
Aug 02 2015 22:14
I've been compiling with 2015 for several months now (the release candidates, with /analyze turned on) and am not seeing that issue. I think some other code analysis tool complained about that but I either fixed it or determined the analysis was wrong...
I'm re-running analyze and full build on 2015 to see what it says
Jason Turner
@lefticus
Aug 02 2015 22:22
Ah, it only shows that with a Release build, not a debug build
that's really weird
Jason Turner
@lefticus
Aug 02 2015 22:30
And to answer your question - it can only lead to issues if the user is doing something dumb - and I cannot prevent that. Something like: Boxed_Value &bv = boxed_cast<Boxed_Value &>(var(5))
yes, that would cause an issue but I don't think I can totally prevent the user from doing something like that
Andreas Reischuck
@arBmind
Aug 02 2015 22:33
@lefticus Are you sure? - If I register a conversion like std::string to QString and I try a & conversion - I would expect that you will protect me from my stupidity :)
After all it may be a value returned from a dynamically loaded script
@lefticus There is no official Qt for MSVC2015 - I only compiled the release version of Qt - Who needs debug?
Jason Turner
@lefticus
Aug 02 2015 22:36
I try really hard to protect you. The code that sets up the boxed_cast during a function call with conversions (like the case you are mentioning) actually saves a reference to the input value to make sure it's not popped from the stack prematurely
(then pops the stored references after the function call has completed - and yes there are tests to make sure I don't break that feature)
But it's always going to be possible to break it somehow I'm sure
Andreas Reischuck
@arBmind
Aug 02 2015 22:39
t_conversions->boxed_type_conversion<Type>(bv) this will generate an intermediate value
That is nowhere else on the stack...
I see you store it to the m_conversion_saves
Jason Turner
@lefticus
Aug 02 2015 22:42
yes
Andreas Reischuck
@arBmind
Aug 02 2015 22:42
But it is only active during a function call... not when my C++ code uses it
Jason Turner
@lefticus
Aug 02 2015 22:42
Right
Andreas Reischuck
@arBmind
Aug 02 2015 22:42
I would suggest to mark converted values as temporaries
Jason Turner
@lefticus
Aug 02 2015 22:42
I don't think there's any way I can protect you from that
Andreas Reischuck
@arBmind
Aug 02 2015 22:43
until they are stored either in a User_Boxed-Value or a variable
And temporaries are not allowed to convert to bare adresses or pointers
only shared_pointer and Boxed_Value are allowed
As I said it's really easy to run into these deadly conversions
Jason Turner
@lefticus
Aug 02 2015 22:47
well, just for the record it was only complaining about conversion to Boxed_Value &
not any of the cases you are talking about
Andreas Reischuck
@arBmind
Aug 02 2015 22:49
It's hard to say what exactly triggered the warning
Jason Turner
@lefticus
Aug 02 2015 22:49
no, I know. I just fixed it
well, got it to be quiet
Debating if I'm going to commit it. Probably wil
l
Andreas Reischuck
@arBmind
Aug 02 2015 22:50
Is it ugly?
Jason Turner
@lefticus
Aug 02 2015 22:50
I'm just returning a std::reference_wrapper<Boxed_Value> instead of a Boxed_Value &
I'm also debating if I can implement the "mark as temporary" solution you suggest without creating a different problem
I think it would probably work. I'll make a note of it to look at tomorrow
Andreas Reischuck
@arBmind
Aug 02 2015 22:52
Thank you...