[llvm-bugs] [Bug 51661] New: dllexported subclass causes implicit instantiation of base class static fields

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 28 14:01:34 PDT 2021


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

            Bug ID: 51661
           Summary: dllexported subclass causes implicit instantiation of
                    base class static fields
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: skyostil at chromium.org
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The following code fails to build with clang-cl 14.0.0 (ee659383):

  // Define a template with a static field.
  template <typename T>
  struct Base {
    static int member;
  };

  // Define a dllexported subclass using the template.
  struct __declspec(dllexport) Sub: public Base<int> {};

  // Declare storage for the static member:
  template <>
  int __declspec(dllexport) Base<int>::member;

This fails with:

  test.cc(12,16): error: explicit specialization of 'member' after
instantiation
  int Base<int>::member;

  test.cc(4,16): note: implicit instantiation first required here
    static int member;

The same code builds with CL 19.29.30037, or if I remove the dllexport
declaration from `Sub`, or if I move the static member declaration above the
definition of `Sub`.

-- 
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/20210828/4a16a657/attachment.html>


More information about the llvm-bugs mailing list