[Bug c++/16245] New: Invalid converion of array types.

vassili_bourdo at softhome dot net gcc-bugzilla@gcc.gnu.org
Mon Jun 28 13:55:00 GMT 2004


The code:
-------------------------------------------
typedef char(arr_type)[10];
typedef char(&arr_ref)[10];

arr_ref fn()
{
	static arr_type a = {1,2,3,4};
	return arr_ref(a);
	//return a;
}
-------------------------------------------
Fails to compile on Mingw GCC-3.4.0 with diagnostics:
-------------------------------------------
bug.cxx: In function `char (& fn())[10]':
bug.cxx:7: error: conversion to non-const reference type `char (&)[10]' from 
rvalue of type `char*'
bug.cxx:7: error: invalid initialization of non-const reference of type 'char 
(&)[10]' from a temporary of type 'char*'
-------------------------------------------
However if replace "return arr_ref(a);" with "return a;" it compiles

-- 
           Summary: Invalid converion of array types.
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vassili_bourdo at softhome dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16245



More information about the Gcc-bugs mailing list