function returning lvalue instead of rvalue

Simpson, Kenneth S kenneth.s.simpson@intel.com
Mon Jul 17 18:24:00 GMT 2000


Hi,
  The following program demonstrates either a bug in gcc or a misconception
of mine.

  I believe that case 1 should fail in exactly the same way as case 3,
meaning that the string returned from the function is not an lvalue.
Is this the gcc C extension of lvalues?
If so, how can I disable it?

gcc version 2.95.2 19991024 (release)
g++ -Wall -W -ansi -pedantic-errors bug_report.C

Thanks,
-Kenny (speaking only for myself, not my employer nor anyone else)

----------------------------------------------------------------
#include <string>

template <typename _T>
_T return_type() { return _T();}

int main()
{
  // case 1
  return_type<std::string>() += "hi"; // compiles with no warnings or errors

  // case 2
  // this gives a "bug_report.C:13: no match for `const string = const
char[3]'"
  //return_type<std::string const>() = "hi";

  // case 3
  // this gives a "bug_report.C:17: non-lvalue in assignment"
  //return_type<int>() = 0;

  // case 4
  // this gives a "bug_report.C:21: non-lvalue in assignment"
  //return_type<int const>() = 0;

  return 0;
}



More information about the Gcc-bugs mailing list