Skip to content

About nested class inside a class template #555

@GKxxUCAS

Description

@GKxxUCAS
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions