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

About nested class inside a class template #555

Closed
GKxxQAQ opened this issue Aug 4, 2023 · 1 comment
Closed

About nested class inside a class template #555

GKxxQAQ opened this issue Aug 4, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@GKxxQAQ
Copy link

GKxxQAQ commented Aug 4, 2023

template <typename T>
struct foo {
  struct bar;
};

template <typename T>
struct foo<T>::bar {};

int main() {
  foo<int>::bar b;
}

Cppinsights gives the following output:

template <typename T>
struct foo {
  struct bar;
};

/* First instantiated from: a.cpp:12 */
#ifdef INSIGHTS_USE_TEMPLATE
template <>
struct foo<int> {
  struct bar {
    // inline constexpr bar() noexcept = default;
  };
};

#endif

struct foo<T>::bar {};

int main() {
  foo<int>::bar b;
  return 0;
}

template <typename T> is missing for struct foo<T>::bar{};. This can cause problems when the template parameter name T hides some global name, which makes struct foo<T>::bar {}; a specialization.

@andreasfertig andreasfertig added the bug Something isn't working label Sep 7, 2023
@andreasfertig
Copy link
Owner

Hello @GKxxQAQ,

thanks for spotting and reporting this issue.

Foxing this appeared problematic initially because when transforming the out-of-line definition of bar, only foo is the class template. However, I found a way.

A fix is on its way.

Andreas

andreasfertig added a commit that referenced this issue Sep 7, 2023
Fixed #555: Transform a out-of-line struct declared inside a class template.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants