Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang assert: "Assertion `getDepthAndIndex(NewParam).first == 0 && "Unexpected template parameter depth"' failed." #128691

Open
hokein opened this issue Feb 25, 2025 · 4 comments · May be fixed by #128704
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@hokein
Copy link
Collaborator

hokein commented Feb 25, 2025

https://godbolt.org/z/TPjf1YYY3

A regression from #111143

template <typename = void>
class NewDeleteAllocator;

template <>
struct NewDeleteAllocator<> {
  template <typename>
  NewDeleteAllocator();
};

template <typename>
struct NewDeleteAllocator : NewDeleteAllocator<> {
  using NewDeleteAllocator<>::NewDeleteAllocator;
};

void test() { NewDeleteAllocator abc; }
@hokein hokein added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Feb 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 25, 2025

@llvm/issue-subscribers-clang-frontend

Author: Haojian Wu (hokein)

https://godbolt.org/z/TPjf1YYY3

A regression from #111143

template &lt;typename = void&gt;
class NewDeleteAllocator;

template &lt;&gt;
struct NewDeleteAllocator&lt;&gt; {
  template &lt;typename&gt;
  NewDeleteAllocator();
};

template &lt;typename&gt;
struct NewDeleteAllocator : NewDeleteAllocator&lt;&gt; {
  using NewDeleteAllocator&lt;&gt;::NewDeleteAllocator;
};

void test() { NewDeleteAllocator abc; }

@hokein
Copy link
Collaborator Author

hokein commented Feb 25, 2025

cc @zyn0217

@zyn0217
Copy link
Contributor

zyn0217 commented Feb 25, 2025

NewParam->dump()
TemplateTypeParmDecl 0x5555631a8e98 <128691.cpp:8:13> col:21 typename depth 32767 index 1

Which suggests the NewDepth we've calculated is wrong.

@zyn0217
Copy link
Contributor

zyn0217 commented Feb 25, 2025

So... the constructor for which we're trying to synthesize a deduction guide comes from the explicit specialization template <> struct NewDeleteAllocator<>, which has an empty template parameter list. As a result, the function template (the constructor) lvies at depth 0. When building a deduction guide within a class template, we assume there's always at least one level of template depth and therefore use Param->getDepth() - 1, which overflows in this case.

(We should have been doing this wrong prior to 20, but it didn't crash because it called Decl::getTemplateDepth(), which returns 0 for the transformed template parameter declaration)

@EugeneZelenko EugeneZelenko added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants