[llvm-bugs] [Bug 43270] New: Improper handling of __declspec(selectany) constexpr in clang-cl /std:c++17

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 10 14:19:16 PDT 2019


            Bug ID: 43270
           Summary: Improper handling of __declspec(selectany) constexpr
                    in clang-cl /std:c++17
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: epastor at google.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Created attachment 22484
  --> https://bugs.llvm.org/attachment.cgi?id=22484&action=edit
Minimal reproduction

For MSVC compatibility, clang-cl replicates a non-standard behavior creating
implicit definitions for static const (including constexpr) members.

According to Microsoft documentation, to accommodate these, we're supposed to
use __declspec(selectany) as a guard on the out-of-class definition. [1]

However... if we pass /std:c++17 or /std:c++2a to clang-cl when compiling a
source file including an out-of-class definition, clang-cl emits the following

selectany.cc(13,1): warning: attribute declaration must precede definition
SELECTANY constexpr int CMyClass::val;
selectany.cc(8,30): note: expanded from macro 'SELECTANY'
#define SELECTANY __declspec(selectany)
selectany.cc(3,24): note: previous definition is here
  static constexpr int val = 0;

No such warning appears if we pass /std:c++14 instead.

Minimal reproduction attached.


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/20190910/12474d97/attachment.html>

More information about the llvm-bugs mailing list