Community
cancel
Showing results for 
Search instead for 
Did you mean: 
gn164
Beginner
46 Views

icpc program fails with double free when it shouldn't

Hi

 

The following program fails with " double free or corruption" error. I believe it is a compiler bug. Could someone please have a look at it.

icpc version 14.0.1 (gcc version 4.7.0 compatibility)

icpc -std=c++11 -O2 -g streamtest.cpp

 

#include <iostream>
#include <stdio.h>
#include <sstream>

struct Path
{
   Path()
   {
      _host = "host";
      _dir =  "dir";
      _file = "file";
   }

   std::string host()
   {
      return _host;
   }

   std::string path() {

      std::string ret = host() + _dir + _file;
      return  ret;
   }

   private:
      std::string _dir;
      std::string _file;
      std::string _host;
};

int main () {

  Path path;
  std::string p = path.path();

  return 0;

}

0 Kudos
2 Replies
Viet_H_Intel
Moderator
46 Views

I don't have a machine with GCC 4.7 installed, but I could reproduce it with GCC 4.8.1

vahoang@orcsle100:/tmp$ icpc -std=c++11 -O2 -g t.cpp -V
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.1.106 Build 20131008

Edison Design Group C/C++ Front End, version 4.6 (Oct  8 2013 19:20:39)
Copyright 1988-2013 Edison Design Group, Inc.

GNU ld version 2.20.51.0.2-5.11.el6 20091009
vahoang@orcsle100:/tmp$ gcc -v
gcc version 4.8.1 (GCC)
vahoang@orcsle100:/tmp$
 

Secondly, we are no longer supported Intel compiler version 14.0.

Viet_H_Intel
Moderator
46 Views

Sorry for the typo. "could" where I meant "could not".