Skip to content

[clang] crashes and misbehavior with member function template explicit specialization #111266

@mizvekov

Description

@mizvekov

Clang crashes compiling the following valid example: https://godbolt.org/z/Kx916caT7

template<class T> struct S {
  template<int> auto foo();
  template<> auto foo<1>() {
    return [](auto x) { return x; };
  }
};
template struct S<void>;

What happens is that when instantiating the members of S, we lose track of the specialization kind of foo<1>, leading to us using the explicit specialization argument when instantiating the function definition.

The behavior for explicit instantiation doesn't match MSVC and EDG as well: https://godbolt.org/z/ejehb88zc

template<class T> struct A {
  int x;
  template<class U = void> static void f();
  template<> void f<int>() { (void)this->x; }
};
template struct A<int>;

Here clang eagerly instantiates f<int> and complains about usage of this in static function, while MSVC / EDG only do so when the definition is actually used.

Metadata

Metadata

Assignees

Labels

c++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crash-on-validdiverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issueextension:microsoft

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions