<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 - __uuidof at a template argument causes infinite template instantiation"
   href="https://bugs.llvm.org/show_bug.cgi?id=40395">40395</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__uuidof at a template argument causes infinite template instantiation
          </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++'17
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mail+llvm@tzik.jp
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Extra SubstNonTypeTemplateParmExpr around __uuidof causes infinite template
instantiation.

Here is a repro below. The output contains multiple instantiation of
A<&__uuidof(B)> with different AST around __uuidof.

The AST of |piid| on the second instantiation is:
| | |-TemplateArgument expr
| | | `-ConstantExpr 0x1f94990 <line:6:26> 'const _GUID *'
| | |   `-SubstNonTypeTemplateParmExpr 0x1f94970 <col:26> 'const _GUID *'
| | |     `-ConstantExpr 0x1f630c8 <line:10:5, col:16> 'const _GUID *'
| | |       `-UnaryOperator 0x1f630b0 <col:5, col:16> 'const _GUID *' prefix
'&' cannot overflow
| | |         `-CXXUuidofExpr 0x1f63080 <col:6, col:16> 'const _GUID' lvalue

And it on the third instantiation is:
| | |-TemplateArgument expr
| | | `-ConstantExpr 0x1f97678 <line:6:26> 'const _GUID *'
| | |   `-SubstNonTypeTemplateParmExpr 0x1f97658 <col:26> 'const _GUID *'
| | |     `-ConstantExpr 0x1f94990 <col:26> 'const _GUID *'
| | |       `-SubstNonTypeTemplateParmExpr 0x1f94970 <col:26> 'const _GUID *'
| | |         `-ConstantExpr 0x1f630c8 <line:10:5, col:16> 'const _GUID *'
| | |           `-UnaryOperator 0x1f630b0 <col:5, col:16> 'const _GUID *'
prefix '&' cannot overflow
| | |             `-CXXUuidofExpr 0x1f63080 <col:6, col:16> 'const _GUID'
lvalue

That is, the value of __uuidof is wrapped by SubstNonTypeTemplateParmExpr
multiple times, and A<&__uuidof(B)> is instantiated for each variant of wrap
level.

$ clang++ -ftemplate-depth=3 -Xclang -ast-dump -fms-extensions -fsyntax-only
-std=c++17 foo.cc
---- foo.cc ----
struct _GUID {};
struct __declspec(uuid("{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}")) B {};

template <const _GUID* piid>
struct A {
  virtual void baz() { A<piid>(); }
};

void f() {
  A<&__uuidof(B)>();
}
----</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>