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++/32832] New: Seg fault on member function that does not return a val


The following code shows the error...

#include <vector>
#include <list>
#include <map>
#include <iostream>
#include <string>

using namespace std;

class foo {
public: 
    vector <string> bar (vector<string> s) {
         //nothing returned but g++ never complains
    }
};

int main()
{
    string strs[] = {"a", "b"};
    foo f;
    f.bar(vector<string>(strs, strs + 2));
}

------------------------------
aewhite@aewhite-laptop:~/working/TC$ g++ -o g_bug g_bug.cpp
aewhite@aewhite-laptop:~/working/TC$ ./g_bug
Segmentation fault
------------------------------

#include <vector>
#include <list>
#include <map>
#include <iostream>
#include <string>

using namespace std;

class foo {
public: 
    vector <string> bar (vector<string> s) {
        return vector<string>(); // fixes problem!?
    }
};

int main()
{
    string strs[] = {"a", "b"};
    foo f;
    f.bar(vector<string>(strs, strs + 2));
}
-----------------------------
aewhite@aewhite-laptop:~/working/TC$ g++ -o g_bug g_bug.cpp
aewhite@aewhite-laptop:~/working/TC$ ./g_bug
-----------------------------

Note that with -Wall it warn, but will not report any error...
---------------------------------
aewhite@aewhite-laptop:~/working/TC$ g++ -Wall -o g_bug g_bug.cpp
g_bug.cpp: In member function ?std::vector<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > > foo::bar(std::vector<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >)?:
g_bug.cpp:12: warning: no return statement in function returning non-void
g_bug.cpp:12: warning: control reaches end of non-void function
--------------------------------------------

I am using Ubuntu dapper with their version of gcc which I would assume to be
pretty up to date. Sorry if this is a repeat, I didn't quite know how to search
for this particular bug since it occurs at run time.


-- 
           Summary: Seg fault on member function that does not return a val
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: CyrusOmega at gmail dot com


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


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