Search

compiler template declaration/definition mismatch error by Mumau

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 640228
Opened: 1/29/2011 7:54:41 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
The compiler is generating an invalid error (2244) while compiling the code listed below in steps to reproduce. I have consolidated the code that is causing the error into a concise example for demonstration purposes. The compiler is not able to correctly match the class method definition to the class method declaration.

I do have a work around that is not ideal.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Reliability

Steps to reproduce

// Copy and paste this section to a .cpp file and try to compile it
// Toggling the ERROR_FLAG macro will enable and disable the code that causes
// the linker error.
#define ERROR_FLAG (1)

template<typename T>
class Compare
{
public:
    bool operator () (T const& left, T const& right) const
    {
        return left < right;
    }
};

template<typename T>
class Node
{
public:
};

template<typename T>
class TreeCore
{
public:
};

template<typename T,
         typename Comp_t = Compare<T>,
         template<typename> class Core_t = TreeCore>
class Tree
{
public:
    typedef Node<T> Node_t;
};

template<typename T>
class TestData
{
public:
};

template<template<typename, typename,
                 template<typename> class> class Tree_t,
         template<typename> class Core_t>
class TreeBaseTest
{
public:
    // the compiler does not complain about this method
    template<typename T, typename Comp1_t, typename Comp2_t>
    int verifyContents (
        Tree_t<T, Comp1_t, Core_t> const& tree, Comp2_t const& comp,
        TestData<T> const* const pData, size_t count) const;

#if (ERROR_FLAG)
     // the compiler does not match this decalaration with the definition
    template<typename T, typename Comp_t>
    int verifyBalance (
        typename Tree_t<T, Comp_t, Core_t>::Node_t const* pNode,
        int* pHeightOut) const;
#endif
};

template<template<typename, typename,
                 template<typename> class> class Tree_t,
         template<typename> class Core_t>
template<typename T, typename Comp1_t, typename Comp2_t>
int TreeBaseTest<Tree_t, Core_t>::verifyContents (
    Tree_t<T, Comp1_t, Core_t> const& tree, Comp2_t const& comp,
    TestData<T> const* const pData, size_t count) const
{
    return 0;
}

#if (ERROR_FLAG)
// the compiler does not match this definition with the declaration
template<template<typename, typename,
                 template<typename> class> class Tree_t,
         template<typename> class Core_t>
template<typename T, typename Comp_t>
int TreeBaseTest<Tree_t, Core_t>::verifyBalance (
    typename Tree_t<T, Comp_t, Core_t>::Node_t const* pNode,
    int* pHeightOut) const
{
    return 0;
}
#endif

int main ()
{
    TreeBaseTest<Tree, TreeCore> treeBaseTest;
    Tree<int> tree;
    TestData<int> testData[1];
    Tree<int>::Node_t node;
    int height;

#if (0)
    // this won't compile due to previous errors
    treeBaseTest.verifyBalance<T, Compare<T> > (&node, &height);
#endif

    return treeBaseTest.verifyContents (tree, Compare<int> (), testData, 0);
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

1>------ Build started: Project: TemplateError, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\public\documents\programming projects\templateerror\templateerror\main.cpp(86): error C2244: 'TreeBaseTest<Tree_t,Core_t>::verifyBalance' : unable to match function definition to an existing declaration
1>         definition
1>         'int TreeBaseTest<Tree_t,Core_t>::verifyBalance(const Tree_t<T,Comp_t,Core_t>::Node_t *,int *) const'
1>         existing declarations
1>         'int TreeBaseTest<Tree_t,Core_t>::verifyBalance(const Tree_t<T,Comp1_t,Core_t>::Node_t *,int *) const'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Expected results

========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
File Attachments
File Name Submitted By Submitted On File Size  
Main.cpp 1/29/2011 2 KB
Main.cpp 1/29/2011 2 KB
Sign in to post a comment.
Posted by Microsoft on 3/8/2011 at 9:41 AM
Hi Mumau:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by Microsoft on 3/1/2011 at 6:20 PM
Hello,

Thank you for reporting this bug. This is indeed our compiler bug for out of line definition of template function with template template parameter list. Some notes in the code below. We will continue investigating this bug and will fix it in a future release.

Thanks,
Ulzii Luvsanbat
Windows C++ Team

template<typename T>
class Compare
{
public:
    bool operator () (T const& left, T const& right) const
    {
        return left < right;
    }
};

template<typename T>
class Node
{
public:
};

template<typename T>
class TreeCore
{
public:
};

template<typename T,
    typename Comp_t = Compare<T>,
    template<typename> class Core_t = TreeCore>
class Tree
{
public:
    typedef Node<T> Node_t;
};

template<typename T>
class TestData
{
public:
};

template<template<typename X1, typename X2, template<typename X3> class> class Tree_t,
         template<typename X4> class Core_t>
class TreeBaseTest
{
public:
    // the compiler does not complain about this method
    template<typename T, typename Comp1_t, typename Comp2_t>
    int verifyContents (Tree_t<T, Comp1_t, Core_t> const& tree, Comp2_t const& comp, TestData<T> const* const pData, size_t count) const;


    // the compiler does not match this decalaration with the definition
    template<typename T, typename BUG>
    int verifyBalance ( typename Tree_t<T, BUG /* HERE!!! It's using wrong template parameter */, Core_t>::Node_t const* pNode, int* pHeightOut) const;

};

template<template<typename, typename, template<typename> class> class Tree_t,
         template<typename> class Core_t>
template<typename T, typename Comp1_t, typename Comp2_t>
int TreeBaseTest<Tree_t, Core_t>::verifyContents ( Tree_t<T, Comp1_t, Core_t> const& tree, Comp2_t const& comp, TestData<T> const* const pData, size_t count) const
{
    return 0;
}


// the compiler does not match this definition with the declaration
template<template<typename X1, typename X2, template<typename X3> class> class Tree_t,
         template<typename X4> class Core_t>
template<typename T, typename Comp_t>
int TreeBaseTest<Tree_t, Core_t>::verifyBalance ( typename Tree_t<T, Comp_t, Core_t>::Node_t const* pNode, int* pHeightOut) const
{
    return 0;
}


int main ()
{
    TreeBaseTest<Tree, TreeCore> treeBaseTest;
    Tree<int> tree;
    TestData<int> testData[1];
    Tree<int>::Node_t node;
    int height;

#if (0)
    // this won't compile due to previous errors
    treeBaseTest.verifyBalance<T, Compare<T> > (&node, &height);
#endif

    return treeBaseTest.verifyContents (tree, Compare<int> (), testData, 0);
}
Posted by Microsoft on 1/30/2011 at 7:12 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 1/29/2011 at 8:13 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.