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 sanitizer/68338] New: tsan report error about c++11 static local initialize


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68338

            Bug ID: 68338
           Summary: tsan report error about c++11 static local initialize
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dushistov at mail dot ru
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
  Target Milestone: ---

With code like this:

#include <thread>
#include <iostream>
#include <string>

std::string message()
{
        static std::string msg("hi");
        return msg;
}

int main()
{
        std::thread t1([]() { std::cout << message() << "\n"; });
        std::thread t2([]() { std::cout << message() << "\n"; });

        t1.join();
        t2.join();
}

compile like this:
g++ -O3 -g3 -fsanitize=thread -Wall -std=c++11 -pthread -Wextra test.cpp

according to c++11 statnadard such code should be thread safe,

at the same time if replate g++(gcc 5.2) by clang++(clang 3.7)
it does run without any reported failures.

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