[Bug c++/81526] New: In structure defined inside template function, template arguments inside the structure are not accepted to have template members.

ramon.garcia.f+gcc at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Jul 23 23:03:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81526

            Bug ID: 81526
           Summary: In structure defined inside template function,
                    template arguments inside the structure are not
                    accepted to have template members.
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ramon.garcia.f+gcc at gmail dot com
  Target Milestone: ---

Created attachment 41815
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41815&action=edit
Preprocessed source.

While building Microsoft Bond (http://github.com/Microsoft/bond) source
(release 0b22da6371098fefd921291bfb7c211a33191121 ), I had trouble with what
looks like a GCC bug. I posted a bug report at
https://github.com/Microsoft/bond/issues/538

The conflicting source is
https://github.com/Microsoft/bond/blob/5454d52ea0b55ee696e1bd2727d5492379abe06f/cpp/inc/bond/core/value.h

The issue happens with a template function DeserializeElement.

template <typename Protocols, typename X, typename I, typename T>
typename boost::enable_if<require_modify_element<X> >::type
inline DeserializeElement(X& var, const I& item, const T& element)
{
    struct Deserialize
    {
        Deserialize(const T& element)
            : element(element)
        {}

        void operator()(typename element_type<X>::type& e)
        {
            this->element.template Deserialize<Protocols>(e);
        }

        const T& element;
    };

    modify_element(var, item, Deserialize(element));
}

The error message is 

In file included from /bond/cpp/inc/bond/core/parser.h:8:0,
                 from /bond/cpp/inc/bond/core/apply.h:9,
                 from /bond/cpp/inc/bond/core/bond.h:7,
                 from /bond/build/cpp/bond/core/bond_apply.h:16,
                 from /bond/build/cpp/bond/core/bond_apply.cpp:13:
/bond/cpp/inc/bond/core/value.h: In member function ‘void
bond::DeserializeElement(X&, const I&, const
T&)::Deserialize::operator()(typename bond::element_type<T>::type&)’:
/bond/cpp/inc/bond/core/value.h:644:57: error: non-template type ‘Deserialize’
used as a template
             this->element.template Deserialize<Protocols>(e);

GCC cannot figure out that element.template Deserialize is a template function.

The issue disappears completely if the structure Deserialize is moved out of
the local function.


I am posting preprocessed source of a slightly simplified (replaced
boost::enable_if with std::enable_if).

I also reproduced the problem with GCC 7.1 and 6.3.0 in my Debian GNU/Linux


More information about the Gcc-bugs mailing list