<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 --- - clang assertion failure when trying to infer generic lambda return type from undefined variable"
   href="https://llvm.org/bugs/show_bug.cgi?id=25180">25180</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang assertion failure when trying to infer generic lambda return type from undefined variable
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>fabian.gruber@fadeopolis.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>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=15080" name="attach_15080" title="Test case cpp file that triggers the assertion failure">attachment 15080</a> <a href="attachment.cgi?id=15080&action=edit" title="Test case cpp file that triggers the assertion failure">[details]</a></span>
Test case cpp file that triggers the assertion failure

Clang dies with an assertion failure in the frontend while trying to infer the
type of a generic lambda.
The lambda consists of an if-statement in which the else branch is just `return
baz;' where baz is an undefined variable.

This only happens when compiling with `-std=c++14'.
With `-std=c++11' an undefined variable error is reported.

I managed to reproduce this bug with the Ubuntu clang/llvm 3.8 package from
llvm.org [3.8.0-svn250077-1~exp1 (trunk)] and a version built from trunk
[(<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
52bc812d7e056333f2a456b8fe8a0dba93e09bfd)(<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
0dcd516b64fa28ad83e5df4c71c5852cfe9d5683)].

== preprocessed testcase:

# 1 "<built-in>"
# 1 "clang_bug.cpp"

bool quoz();

int foo() {
  auto bar = []() {
    if (quoz()) {
      // The bug is also triggered even if there are compiler errors in this
      // branch of the if-statement.
      // I.e. using an undefined variable, etc.
      // The error mustn't be `severe' enough to stop clang from looking at the
      // else-branch, though.

      // in trunk clang-3.8 (52bc812d7e056333f2a456b8fe8a0dba93e09bfd) the bug
      // is not triggered if the if-statement is not present.
      // on clang-3.8 from the LLVM Ubuntu repo (3.8.0-svn250077-1~exp1) just
      // `return baz` is enough.

      return "default";
    } else {
      // `baz' is not defined in this scope!
      // If I define name it stops crashing.
      return baz;
    }
  };
}

== crash reproducer for trunk clang
= (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a> 52bc812d7e056333f2a456b8fe8a0dba93e09bfd)
= (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a> 0dcd516b64fa28ad83e5df4c71c5852cfe9d5683)

# Crash reproducer for clang version 3.8.0 (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
52bc812d7e056333f2a456b8fe8a0dba93e09bfd) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
0dcd516b64fa28ad83e5df4c71c5852cfe9d5683)
# Driver args: "-std=c++14" "clang_bug.cpp"
# Original command:  "/home/fader/workspace/.build/debug/llvm/bin/clang-3.8"
"-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all"
"-disable-free" "-main-file-name" "clang_bug.cpp" "-mrelocation-model" "static"
"-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose"
"-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu"
"x86-64" "-dwarf-column-info" "-resource-dir"
"/home/fader/workspace/.build/debug/llvm/bin/../lib/clang/3.8.0"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/backward"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/home/fader/workspace/.build/debug/llvm/bin/../lib/clang/3.8.0/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-std=c++14" "-fdeprecated-macro" "-fdebug-compilation-dir"
"/home/fader/Desktop" "-ferror-limit" "19" "-fmessage-length" "134"
"-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-o"
"/tmp/clang_bug-64f932.o" "-x" "c++" "clang_bug.cpp"
 "/home/fader/workspace/.build/debug/llvm/bin/clang-3.8" "-cc1" "-triple"
"x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free"
"-main-file-name" "clang_bug.cpp" "-mrelocation-model" "static"
"-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose"
"-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu"
"x86-64" "-dwarf-column-info" "-std=c++14" "-fdeprecated-macro" "-ferror-limit"
"19" "-fmessage-length" "134" "-fobjc-runtime=gcc" "-fcxx-exceptions"
"-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-x" "c++"
"clang_bug-6b2789.cpp"


== crash reproducer for clang from llvm.org Ubuntu package

# Crash reproducer for Ubuntu clang version 3.8.0-svn250077-1~exp1 (trunk)
(based on LLVM 3.8.0)
# Driver args: "-std=c++14" "clang_bug.cpp"
# Original command:  "/usr/lib/llvm-3.8/bin/clang" "-cc1" "-triple"
"x86_64-pc-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free"
"-disable-llvm-verifier" "-main-file-name" "clang_bug.cpp" "-mrelocation-model"
"static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno"
"-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array"
"-target-cpu" "x86-64" "-target-linker-version" "2.25" "-dwarf-column-info"
"-resource-dir" "/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/backward"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include" "-internal-externc-isystem"
"/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include"
"-internal-externc-isystem" "/usr/include" "-std=c++14" "-fdeprecated-macro"
"-fdebug-compilation-dir" "/home/fader/Desktop" "-ferror-limit" "19"
"-fmessage-length" "134" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-o"
"/tmp/clang_bug-9f98d4.o" "-x" "c++" "clang_bug.cpp"
 "/usr/lib/llvm-3.8/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu"
"-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier"
"-main-file-name" "clang_bug.cpp" "-mrelocation-model" "static"
"-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose"
"-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu"
"x86-64" "-target-linker-version" "2.25" "-dwarf-column-info" "-std=c++14"
"-fdeprecated-macro" "-ferror-limit" "19" "-fmessage-length" "134"
"-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-x" "c++"
"clang_bug-a32268.cpp"</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>