<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Assigning a gsl::span<const int> to a gsl::span<int> const causes segmentation fault during compilation."
   href="https://llvm.org/bugs/show_bug.cgi?id=28598">28598</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Assigning a gsl::span<const int> to a gsl::span<int> const causes segmentation fault during compilation.
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.8
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ibbles@hotmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16760" name="attach_16760" title="Archive containing main.cpp producing the crash, output from crashed compilation and log files created by clang.">attachment 16760</a> <a href="attachment.cgi?id=16760&action=edit" title="Archive containing main.cpp producing the crash, output from crashed compilation and log files created by clang.">[details]</a></span>
Archive containing main.cpp producing the crash, output from crashed
compilation and log files created by clang.

# Overview

Using Microsoft's implementation of the Guidelines Support Library, available
at <a href="https://github.com/Microsoft/GSL">https://github.com/Microsoft/GSL</a>.

Initializing a local variable of type `span<int> const` with the return value
of a function returning a `span<int const>` causes the compiler crash with a
segmentation fault. Notice the misplaced `const` in the declaration of the
local variable.

Attached is a reduced, i.e., with no dependence on GSL, version of span<T>
along with a use case that causes the crash, the output I get when I compile
and a pair of files that the clang error handler created.


# Steps to reproduce

Build the attached main.cpp file using

clang++-3.8 -std=c++14 -c -o main.o main.cpp


# Actual result

Crash in clang. Last few frames of stack trace is

#0 0x00007f6da13efcb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/lib/x86_64-linux-gnu/libLLVM-3.8.so.1+0x5a4cb8)
#1 0x00007f6da13edf56 llvm::sys::RunSignalHandlers()
(/usr/lib/x86_64-linux-gnu/libLLVM-3.8.so.1+0x5a2f56)
#2 0x00007f6da13ee0b9 (/usr/lib/x86_64-linux-gnu/libLLVM-3.8.so.1+0x5a30b9)
#3 0x00007f6da0510250 (/lib/x86_64-linux-gnu/libc.so.6+0x35250)
#4 0x00000000013b3607 (/usr/lib/llvm-3.8/bin/clang+0x13b3607)
#5 0x00000000013bb322 (/usr/lib/llvm-3.8/bin/clang+0x13bb322)
#6 0x00000000013bd729
clang::FormatASTNodeDiagnosticArgument(clang::DiagnosticsEngine::ArgumentKind,
long, llvm::StringRef, llvm::StringRef,
llvm::ArrayRef<std::pair<clang::DiagnosticsEngine::ArgumentKind, long> >,
llvm::SmallVectorImpl<char>&, void*, llvm::ArrayRef<long>)
(/usr/lib/llvm-3.8/bin/clang+0x13bd729)
#7 0x00000000006bc6b7 clang::Diagnostic::FormatDiagnostic(char const*, char
const*, llvm::SmallVectorImpl<char>&) const
(/usr/lib/llvm-3.8/bin/clang+0x6bc6b7)

Full stack trace available in the attachments.


# Expected results

Error message pointing out the invalid conversion.


# Build date and platform

Ubuntu 15.10.

clang from llvm's Ubuntu repositories:
deb <a href="http://llvm.org/apt/wily/">http://llvm.org/apt/wily/</a> llvm-toolchain-wily-3.8 main.

clang version 3.8.1-svn271772-1~exp1 (branches/release_38)
Target: x86_64-unknown-linux-gnu



# Additional builds and platforms

Using clang++-3.7 I get no crash and the following expected output:

$ clang++-3.7 -std=c++14 -c -o main.o main.cpp
main.cpp:15:7: error: cannot initialize a member subobject of type
'add_pointer_t<int>' with an lvalue of type 'const add_pointer_t<const int>'
      data_(other.data_)
      ^     ~~~~~~~~~~~
main.cpp:30:26: note: in instantiation of function template specialization
'span<int>::span<const int>' requested here
  span<int> const span = getSpan();
                         ^
1 error generated.</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>