Operating System - HP-UX
1856488 Members
10580 Online
104113 Solutions
New Discussion

Re: aCC emits renark about return value variable being set but not used

 
dritter29
New Member

aCC emits warning about return value variable being set but not used

I have found an issue in aCC.  I am using version:
aCC: HP C/aC++ B3910B A.06.28.01 [Aug 09 2014]

Given this test case

class B
{
public:
struct A
{
  A():
    a_(0)
  {};

  void* a_;
};

};

class F
{
public:
B::A
getA()
{
  B::A ret;
  return ret;
}
};


B::A get()
{
  F f;
  B::A theA = f.getA();
  
  return theA;
}

compiled with this call:

aCC +DD64 +w +std=c++11  -c t.cpp

I see the following warning emitted

"t.cpp", line 30: remark #2550-D: variable "theA" was set but never used
    B::A theA = f.getA();

However because "theA" is the return value it is legal for it to be set but not used.  I feel this warning is an error on the compilers part.

1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: aCC emits renark about return value variable being set but not used

>"theA" is the return value it is legal for it to be set but not used.  I feel this warning is an error on the compilers part.

 

(This has nothing to do with "legal" but with coding style.)

Looks like a minor bug to me but you asked for it by using +w.  :-)

I only see it with +w and +std=c++11, not sure the connection.

And if it was due to the NRV optimization, that should do the warning check before the optimization and +nonrv didn't turn it off.