I have a class representing a buffer of complex valued samples for DSP processing. For some clean looking code this class has the following static member function:
template <typename SampleType>
class SampleBufferComplex
{
public:
...
/** Helper to create one Sample of the buffers SampleType in templated code */
template <typename OriginalType>
static std::complex<SampleType> castToSampleType (OriginalType re, OriginalType im) {return (static_cast<SampleType> (re), static_cast<SampleType> (im)); }
}
This works as expected, however clang throws the following
Warning: "expression result unused".
...
Note:(67, 75) in instantiation of function template specialization 'SampleBufferComplex<float>::castToSampleType<double>' requested here
...
I cannot see where any expression result is unused here, however I want to write 100% warning free code. Am I facing some weird compiler bug or am I overlooking something totally obvious here? Any pointers appreciated!
In the expression
return (static_cast<SampleType> (re), static_cast<SampleType> (im));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The result of the highlighted cast expression is unused. The return statement can be simplified into (assuming the first conversion has no side-effects):
return static_cast<SampleType> (im);
I suspect however, that this is not what you inteded (a good thing you have warnings enabled, eh?). Perhaps you did intend to use real part as well? In that case, you probably should have written instead:
return {static_cast<SampleType> (re), static_cast<SampleType> (im)};
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments