[llvm-bugs] [Bug 41409] New: possible silent bad code generation with inline static data member in clang-cl

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Apr 6 02:08:59 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41409

            Bug ID: 41409
           Summary: possible silent bad code generation with inline static
                    data member in clang-cl
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: other
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++'17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: powerchord at web.de
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

// header.h

#include <iostream>

struct A
{
  A()      { std::cout << "ctor " << this << std::endl; }
  ~A()     { std::cout << "dtor " << this << std::endl; }
  void f() { std::cout << "f " << this << std::endl;  }
};

struct S
{
  inline static A a; // C++17 inline variable, thus also a definition 
};

-----------------------------------------
// TU1.cpp

#include "header.h"

int main()
{
  S::a.f();
}

-----------------------------------------
// TU2.cpp

#include "header.h"

-----------------------------------------
// TU3.cpp

#include "header.h"

-----------------------------------------
// TU4.cpp

#include "header.h"

-----------------------------------------

This program prints (with some random address):

ctor 010D4020
ctor 010D4020
ctor 010D4020
ctor 010D4020
f 010D4020
dtor 010D4020
dtor 010D4020
dtor 010D4020
dtor 010D4020

These are four initializations for the one and only object of A (in fact one
per TU) instead of exactly one (as C++17 demands).

The program should print:

ctor 010D4020
f 010D4020
dtor 010D4020

I first reported this bug for clang-cl 6 (bug 37903 and bug 38171).

MSVC had the same bug, but Microsoft has fixed it (at least in VS2019):
https://developercommunity.visualstudio.com/content/problem/261624/multiple-initializations-of-inline-static-data-mem.html

See also https://stackoverflow.com/q/50982390/8731417.

I wonder why this bug has not been fixed yet because to me it seems pretty
serious. Do I rate that wrong?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190406/a58c28aa/attachment.html>


More information about the llvm-bugs mailing list