This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/64514] New: Error in template instantiation in GCC 4.9, works fine in GCC 4.8
- From: "freddie_chopin at op dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 06 Jan 2015 20:37:39 +0000
- Subject: [Bug c++/64514] New: Error in template instantiation in GCC 4.9, works fine in GCC 4.8
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64514
Bug ID: 64514
Summary: Error in template instantiation in GCC 4.9, works fine
in GCC 4.8
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: freddie_chopin at op dot pl
The test code below works perfectly fine with GCC 4.8 (and 4.7):
--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
#include <type_traits>
template<typename T, T &object, typename... Args>
struct Functor
{
template<float (T::*function)(Args...), Args... args>
struct Inner
{
float operator()() const
{
return (object.*function)(args...);
}
};
};
class Object
{
public:
float someFunction()
{
return {};
}
float someFunctionWithArgument(int)
{
return {};
}
};
Object object;
Functor<Object, object>::Inner<&Object::someFunction> functor1;
Functor<Object, object, int>::Inner<&Object::someFunctionWithArgument, 1>
functor2;
int main()
{
}
--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
However with GCC 4.9 it fails with a rather unhelpful message at the point of
instantiation of functor1:
--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
$ g++ -std=c++11 test.cpp
test.cpp: In instantiation of âstruct Functor<Object, (* & object)>â:
test.cpp:33:24: required from here
test.cpp:7:9: error: wrong number of template arguments (2, should be 1)
struct Inner
^
test.cpp:7:9: error: provided for âtemplate<class T, T& object, class ... Args>
template<float (T::* function)(Args ...), Args ...args> struct Functor<T,
object, Args>::Innerâ
test.cpp:7:9: error: wrong number of template arguments (2, should be 1)
test.cpp:7:9: error: provided for âtemplate<class T, T& object, class ... Args>
template<float (T::* function)(Args ...), Args ...args> struct Functor<T,
object, Args>::Innerâ
test.cpp:33:26: error: âInnerâ in âstruct Functor<Object, (* & object)>â does
not name a template type
Functor<Object, object>::Inner<&Object::someFunction> functor1;
^
--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
If I comment the line with functor1 instantiation, everything else (functor2)
works fine.
At the stackoverflow question I asked (
http://stackoverflow.com/questions/27802404/error-in-template-instantiation-in-gcc-4-9-works-fine-in-gcc-4-8?noredirect=1#comment44015634_27802404
) it was reported that clang 3.5 and Visual Studio 2015 Preview accept this
code, while intel 14 errors out (with an unreported message) and solaris studio
12.4 crashes.
Is there something wrong with this code (which was working for me for over 2
years with older versions) or maybe this is a regression?