<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Improper handling of __declspec(selectany) constexpr in clang-cl /std:c++17"
   href="https://bugs.llvm.org/show_bug.cgi?id=43270">43270</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Improper handling of __declspec(selectany) constexpr in clang-cl /std:c++17
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>epastor@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22484" name="attach_22484" title="Minimal reproduction">attachment 22484</a> <a href="attachment.cgi?id=22484&action=edit" title="Minimal reproduction">[details]</a></span>
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
warning:

=====
selectany.cc(13,1): warning: attribute declaration must precede definition
[-Wignored-attributes]
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.

    [1]:
<a href="https://docs.microsoft.com/en-us/cpp/build/reference/microsoft-extensions-to-c-and-cpp?view=vs-2019">https://docs.microsoft.com/en-us/cpp/build/reference/microsoft-extensions-to-c-and-cpp?view=vs-2019</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>