How to tell what template C++ generated

Viewed 68

I have a C++ template function that looks like

template <class T>
void Item::SetValue(T value){
    std::ostringstream oss;
    oss << value;
    this->value = oss.str();
}

It's been working fine for years until today when my OS (vxworks) threw an SPE exception at me. This basically means I was trying to do floating point arithmetic in a task context that doesn't allow it. This would be fine if I was indeed doing any floating point stuff, but I in fact am just passing a uint32_t to this function. However there are 100s of calls to this function elsewhere from other modules, so who knows what C++ has generated.

I need to know for sure this is the problem (I'm 99% sure) so I want to know if there's any way for me to figure out what function C++ compiler generated for that call. Is there any way?


I may have to ask a new question. I found in the debugger that it is using Item::SetValue<unsigned int> and that it is actually throwing the exception in std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char>>>::do_put (at least, i think). This is the instruction output, and it is failing in evstdd which is definitely in the SPE set. Still don't know why it wants to do any floating point stuff.

Is it possible that

oss << value

Will always treat value as a float, just in case? IE in std::num_put? I don't know how I'll get around this.

Instruction set

2 Answers

Yes, you can use type_traits

if(std::is_same_v(T, uint32_t)) { /*debug info*/ }

The classical solution is to add to the body of the function:

static_assert(!std::is_floating_point_v<T>);
Related