<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 - [clang][ParseEnum] Crashed: Enum with invalid use of incomplete type"
   href="https://bugs.llvm.org/show_bug.cgi?id=51554">51554</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[clang][ParseEnum] Crashed: Enum with invalid use of incomplete type
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>guopeilin1@huawei.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have a test case where clang should give an error message rather than a
crash.
The test command is `clang++ -O2 test.cpp`
The test case is as follows:
enum E { e = E() };

int main() {
  return 0;
}


The error message should be like the following:
test.cpp:1:14: error: invalid use of incomplete type 'E'
enum E { e = E() };
             ^~~
test.cpp:1:6: note: definition of 'E' is not complete until the closing '}'
enum E { e = E() };


However, the trunk get crashed with the assertion
The bug message:
```
./clang/include/clang/AST/Type.h:677: const clang::ExtQualsTypeCommonBase*
clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve
a NULL type pointer"' failed.
```

I did a simple analysis. 
In ParseDecl.cpp:
1. llvm-10: 
   AssignedVal.get(): NULL

2. llvm-12(Context.getLangOpts().RecoveryASTType: default
false)(early-version):
   AssignedVal.get(): RecoveryExpr 0xaaaaba19df20 '<dependent type>'
contains-errors lvalue

3. llvm-12(Context.getLangOpts().RecoveryASTType: default true)
(latest-version, Finally crashed):
   AssignedVal.get()->dump(): RecoveryExpr 0xaaaabb4d9500 'enum E'
contains-errors

In CheckEnumConstant(), EltTy(type: QualType, value: EnumType 0xaaaabb517dd0
'enum E') cannot use getIntWidth(), so crashed. But the code doesn't seem to be
wrong around here.</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>