Skip to content

Incorrect "use 'template' keyword to treat 'xxx' as a dependent template name" inside of virtual member functions of template classes #38395

@duncanhorn

Description

@duncanhorn
Bugzilla Link 39047
Version 7.0
OS Windows NT
CC @steveire

Extended Description

E.g. the following code fails to compile:

template <typename T>
struct special_ptr
{
    T* ptr;

    template <typename U>
    special_ptr<U> as()
    {
        special_ptr<U> result;
        result.ptr = reinterpret_cast<U*>(this->ptr);
        return result;
    }
};

template <typename T>
struct thing
{
    special_ptr<int> intPtr;

    virtual void do_something()
    {
        auto charPtr = this->intPtr.as<char>();
    }
};

struct empty {};

int main()
{
    thing<empty> t;
}

You can also view it at https://godbolt.org/z/ywb5CS. Note that GCC does not have a problem with it. If you change 'thing' to no longer be a class template or if you make 'do_something' no longer virtual, it compiles fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions