This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/14458] New: 3.4 Regression : const_cast suddenly (treated as) temporary?


The following compiles with 3.3.x.  Is does not compile with
3.4 or 3.5 cvs.

~/c++/g++.bugs/bug17>cat test.cc
// Note, though it may seem weird here, in my application this MUST be a char*&.
void f(char const*&) { }

void g(void)
{
  char* p;
  f(const_cast<char const*>(p));
}

~/c++/g++.bugs/bug17>g++-3.3.3 -c test.cc
~/c++/g++.bugs/bug17>


~/c++/g++.bugs/bug17>g++-cvs-3.4 -c test.cc
test.cc: In function `void g()':
test.cc:7: error: invalid initialization of non-const reference of type 'const
char*&' from a temporary of type 'const char*'
test.cc:2: error: in passing argument 1 of `void f(const char*&)'


I didn't check if const_cast<> is now actually calling a
copy constructor, but considering some types have private
copyconstructors or really don't want it to be called, this
makes const_cast<> suddenly a step back from the plain old
C-cast :/

-- 
           Summary: 3.4 Regression : const_cast suddenly (treated as)
                    temporary?
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carlo at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]