6
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;

int main()
{
  int arrA[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  vector<int> vecIntA(arrA, arrA+sizeof(arrA)/sizeof(arrA[0]));

  vector<int> vecIntB(vecIntA.size());

  //copy((vecIntA.rbegin()+3).base(), (vecIntA.rbegin()+1).base(),  vecIntB.begin()); // OK    

  vector<int>::iterator s = (vecIntA.rbegin()+3).base();
  vector<int>::iterator e = (vecIntA.rbegin()+1).base();
  cout << "s: " << *s << ", e: " << *e << endl;
  reverse_copy(s, e,  vecIntB.begin()); // error: function call has aggregate value

  //copy(vecIntB.begin(), vecIntB.end(), ostream_iterator<int>(cout, ","));
  cout << endl;
}

Question> how to fix the issue of "error: function call has aggregate value"?

The above code works under VS2010, but not ubuntu12.04 + clang++3.2 or g++4.6.3

Thank you

// Update //

// Reference: Flags to enable thorough and verbose g++ warnings

g++ $1.cpp -o $1 -g -O -Wall -Weffc++ -pedantic  \
-pedantic-errors -Wextra  -Wall -Waggregate-return -Wcast-align \
-Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion \
-Wdisabled-optimization \
-Werror -Wfloat-equal  -Wformat  -Wformat=2 \
-Wformat-nonliteral -Wformat-security  \
-Wformat-y2k \
-Wimport  -Winit-self  -Winline \
-Winvalid-pch   \
-Wunsafe-loop-optimizations  -Wlong-long -Wmissing-braces \
-Wmissing-field-initializers -Wmissing-format-attribute   \
-Wmissing-include-dirs -Wmissing-noreturn \
-Wpacked  -Wpadded -Wparentheses  -Wpointer-arith \
-Wredundant-decls -Wreturn-type \
-Wsequence-point  -Wshadow -Wsign-compare  -Wstack-protector \
-Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default \
-Wswitch-enum -Wtrigraphs  -Wuninitialized \
-Wunknown-pragmas  -Wunreachable-code -Wunused \
-Wunused-function  -Wunused-label  -Wunused-parameter \
-Wunused-value  -Wunused-variable  -Wvariadic-macros \
-Wvolatile-register-var  -Wwrite-strings \
-std=c++0x
Community
  • 1
  • 1
q0987
  • 34,938
  • 69
  • 242
  • 387
  • Works fine on GCC 4.8.1, both C++03 and C++11. – chris Jun 18 '13 at 04:30
  • 1
    What compiler flags do you use ? – log0 Jun 18 '13 at 04:31
  • [status-norepro] -> http://ideone.com/qPOvty The code looks fine to me. – Billy ONeal Jun 18 '13 at 04:31
  • Can you post the full error message? If nothing else `reverse_copy` is a function template so there should be messages about instantiating it if there's an error there. – Billy ONeal Jun 18 '13 at 04:32
  • ~/Documents/c++11 $ ./rung+ xxx `xxx.cpp: In function ‘int main()’: xxx.cpp:20:39: error: function call has aggregate value [-Werror=aggregate-return] cc1plus: all warnings being treated as errors` – q0987 Jun 18 '13 at 04:34
  • `~/Documents/c++11 $ g++ -o xxx xxx.cpp` works fine. It seems that the flag(i.e.-Waggregate-return) I used has some issues. – q0987 Jun 18 '13 at 04:36
  • 3
    It isn't that the flag has issues; the flag is working as designed. `reverse_copy` does in fact return an aggregate (in this case, an iterator). Whether or not that warning is useful is a different question. – Billy ONeal Jun 18 '13 at 04:37

1 Answers1

10
-Waggregate-return -Werror 

you specified returning aggregate value to be an error. While in theory it is not.

-Waggregate-return
Warn if any functions that return structures or unions are defined or called. (In languages where you can return an array, this also elicits a warning.)

You probably want to remove this flag

log0
  • 10,489
  • 4
  • 28
  • 62