https://bugs.llvm.org/show_bug.cgi?id=40395

            Bug ID: 40395
           Summary: __uuidof at a template argument causes infinite
                    template instantiation
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++'17
          Assignee: unassignedclangb...@nondot.org
          Reporter: mail+l...@tzik.jp
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

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)>();
}
----

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to