Compile:

#include <pthread.h>
// #include <iostream>
int main() {
   pthread_mutexattr_t *attr;
   pthread_mutexattr_init(attr);
   return 0;
}

You get a link error.

Compile:

#include <pthread.h>
#include <iostream>
int main() {
   pthread_mutexattr_t *attr;
   pthread_mutexattr_init(attr);
   return 0;
}

It compiles with no warnings (g++ -Wall testcase.cpp), but when executed,
segfaults. Compiling with -lpthread fixes it, of course, but should this be a
link-time error rather than a runtime error?

This bug was originally reported in Ubuntu's Malone bugtracker:

https://launchpad.net/distros/ubuntu/+source/gcc-4.0/+bug/26663


-- 
           Summary: pthread program compiled without -lpthread crashes.
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: adam dot buchbinder at gmail dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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

Reply via email to