Warning: expression result unused when returning an object with a two argument constructor

PluginPenguin

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!

eerorika

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.

edited at
0

Comments

0 comments
Login to comment

Related

Expression result unused warning in for loop

clang: Fold expression and "expression result unused" warning

How to force “Expression result unused” warning to happen

Xcode 4 warning "Expression result unused” for NSURLConnection

XCode Warning "Expression Result Unused" for mathematical statement

Get rid of warning "Expression Result Unused"

Suppress warning "expression result unused" on a index_sequence

Swift 3 : Warning "Unused result of call" when overriding BecomeFirstResponder

expression result unused in a strcmp

For Loop Expression Result Unused

Not getting any warning when returning NULL as object

Keep getting expression result unused when trying to update UILabel

Error "expression result unused" when using comma operator

move constructor when returning a "chained" object

unused `std::result::Result` that must be used warning

OCMock/OCMVerify - Expression result unused

Type constructor as argument to expression

Warning: Error in dataTableOutput: unused argument (height = "auto")

Errors: expected ';' after expression and expression result unused

Why is gamm returning the error "unused argument (offset= ...)"?

Why there is no temporary object when returning an object through the constructor?

Result of call to function returning Bool is unused

Unsequenced modification warning becomes result unused warning in C++11

Returning one object with the result of two AJAX GET calls

How do I get rid of this 'warning: the expression is unused' warning?

Invalid argument type when returning object from Rxjs switchmap

Why is a static object null when passed as an argument to another class' constructor

Why not use the Result variable directly when returning object?

No clang warning for returning a reference to function argument