Skip to content

Clang fails to merge default template arguments across multiple declarations of a member class template within a class template #160982

@NylteJ

Description

@NylteJ

Similar to #135442, but for class templates.

Clang rejects this code, while MSVC, GCC, and EDG accept it (godbolt):

template <class>
struct Foo {
    template <class T = int>
    struct Bar;

    template <class T>
    struct Bar {};

    using MyBar = Bar<>;
};

template struct Foo<void>;

According to [temp.param]/18, the default arguments for Bar should be merged, so this code should be valid.

Notably, the issue disappears if:

  • the enclosing class is non-template, or
  • the default argument is placed on the definition rather than the declaration (godbolt).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions