[cfe-dev] clang c++0x template function declaration error

Eli Friedman eli.friedman at gmail.com
Mon Jul 4 11:03:46 PDT 2011


On Mon, Jul 4, 2011 at 8:44 AM, Toralf Niebuhr <mamuelle at niebuhrt.de> wrote:
> Hey,
>
>
> I am trying to get the following code to compile and I am not sure
> wether this is my mistake or a compiler bug:
>
> --------------------------------- test.cpp
> template <class T, void (T::*foo)() > class X { };
>
> template <class T>
> auto type_constructor( void (T::*f)() ) -> X< T, f >;
>
>
> class Y
> {
>   public:
>       void bar() {};
> };
>
> int main () {
>   decltype( type_constructor( &Y::bar ) ) x;
> }
> ---------------------------------
>
> It fails with the following message, which doesn't explain what went
> wrong:
>
> $ clang++ -c test.cpp -std=c++0x
>
> test.cpp:14:15: error: no matching function for call to
> 'type_constructor' decltype( type_constructor( &Y::bar ) ) x;
>             ^~~~~~~~~~~~~~~~
> test.cpp:4:6: note: candidate template ignored: substitution failure
> [with T = Y] auto type_constructor( void (T::*f)() ) -> X< T, f >;
>    ^
> test.cpp:14:45: error: C++ requires a type specifier for all
> declarations decltype( type_constructor( &Y::bar ) ) x;
>   ~~~~~~~~                                ^
> 2 errors generated.
>
>
> Can I give you more information?

The declaration of the template type_constructor is broken.  Think
about it this way: type_constructor has one template parameter, so
type_constructor<Y> should refer to a single function; however, you're
trying to specify it as returning multiple types.

-Eli




More information about the cfe-dev mailing list