public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64514] New: Error in template instantiation in GCC 4.9, works fine in GCC 4.8
@ 2015-01-06 20:37 freddie_chopin at op dot pl
  2015-01-12 16:32 ` [Bug c++/64514] " ville.voutilainen at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: freddie_chopin at op dot pl @ 2015-01-06 20:37 UTC (permalink / raw)
  To: gcc-bugs

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?
>From gcc-bugs-return-472335-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Jan 06 20:45:12 2015
Return-Path: <gcc-bugs-return-472335-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 16897 invoked by alias); 6 Jan 2015 20:45:11 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 16405 invoked by uid 55); 6 Jan 2015 20:45:06 -0000
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/64489] A simple struct wrapping a const int is not trivially copyable
Date: Tue, 06 Jan 2015 20:45:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: rejects-valid
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jason at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: ville.voutilainen at gmail dot com
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-64489-4-dHqMpj59bP@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64489-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64489-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-01/txt/msg00329.txt.bz2
Content-length: 495

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd489

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Tue Jan  6 20:44:32 2015
New Revision: 219265

URL: https://gcc.gnu.org/viewcvs?rev!9265&root=gcc&view=rev
Log:
    PR c++/64489
    * class.c (check_field_decls): Make copy assignment operators
    complex only in c++98 mode.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-28 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-06 20:37 [Bug c++/64514] New: Error in template instantiation in GCC 4.9, works fine in GCC 4.8 freddie_chopin at op dot pl
2015-01-12 16:32 ` [Bug c++/64514] " ville.voutilainen at gmail dot com
2015-01-12 20:54 ` [Bug c++/64514] [4.9/5 Regression] " freddie_chopin at op dot pl
2015-01-13 21:05 ` jason at gcc dot gnu.org
2015-01-28 17:21 ` jason at gcc dot gnu.org
2015-01-28 17:22 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).