Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error with GCC #538

Closed
ramon-garcia opened this issue Jul 23, 2017 · 6 comments
Closed

Compile error with GCC #538

ramon-garcia opened this issue Jul 23, 2017 · 6 comments
Labels

Comments

@ramon-garcia
Copy link

While building the master version with GCC, the following error appeared:
In file included from /devel/bond/cpp/inc/bond/core/parser.h:8:0, from /devel/bond/cpp/inc/bond/core/apply.h:9, from /devel/bond/cpp/inc/bond/core/bond.h:7, from /devel/bond/build/cpp/bond/core/bond_apply.h:16, from /devel/bond/build/cpp/bond/core/bond_apply.cpp:13: /devel/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&)’: /devel/bond/cpp/inc/bond/core/value.h:644:57: error: non-template type ‘Deserialize’ used as a template this->element.template Deserialize<Protocols>(e); ^

This looks like a limitation of GCC, though I tested it with GCC 4.9, 6.3.0 and 7.1

Attached a workaround.

fix_gcc_core_value.diff.txt

@ramon-garcia
Copy link
Author

I confirm that this is a bug in GCC.

A testcase fails with GCC and succeeds with Clang (checked by testing in https://gcc.godbolt.org/ )

@chwarr
Copy link
Member

chwarr commented Aug 1, 2017

Thanks for the heads up.
@ara-ayvazyan, you're C++ standards knowledge if better than mine. Do you have time to come up with a cross-compiler, cross-version fix, even if there's a bug in GCC here?

(GCC may be following the standard, and Clang and MSVC are missing this one. Or, it may very well be a bug in GCC...)

There's a bug for this in GCC's bug tracker. It looks like it was opened by @ramon-garcia.

@ara-ayvazyan
Copy link
Contributor

Sure, I'll take a look.

@ara-ayvazyan
Copy link
Contributor

ara-ayvazyan commented Aug 1, 2017

Here is a shorter repro:

template <typename P, typename T>
void foo()
{
    struct X
    {
        void bar()
        {
            this->var.template X<P>();
        }

        T var;
    };
}

I'm not sure which compiler is correct (will need to contact some C++ language lawyer 😃), but this can be resolved by adding T:: just before the template keyword:

this->var.T::template X<P>();

Renaming the struct X is probably safer.

@ramon-garcia
Copy link
Author

@chwarr Yes, I posted the bug in GCC bug tracker.

I couldn't figure out that the name clash between Deserialize struct and Deserialize method is the cause. In this case, renaming the struct is safe solution. Please consider this fix. Even if GCC is wrong, it is the mainstream compiler in Linux. It would take years until new releases include GCC 8 with this bug fixed.

@chwarr
Copy link
Member

chwarr commented Aug 1, 2017

@ramon-garcia, agreed. Let me put together a PR.

chwarr added a commit to chwarr/bond that referenced this issue Aug 1, 2017
Deserialize was used as the name for both a struct and a member
function. This causes some versions of G++ to emit errors, so rename the
helper struct.

Fixes microsoft#538
chwarr added a commit to chwarr/bond that referenced this issue Aug 1, 2017
* Deserialize was used as the name for both a struct and a member
  function. This causes some versions of G++ to emit errors, so rename
  the helper struct. Fixes microsoft#538
* The Protocols template argument could not be deduced in one place
  where bond::SelectProtocolAndApply was called. It is now explicitly
  specified.
@chwarr chwarr added the bug label Aug 3, 2017
tstein pushed a commit that referenced this issue Aug 3, 2017
* Deserialize was used as the name for both a struct and a member
  function. This causes some versions of G++ to emit errors, so rename
  the helper struct. Fixes #538
* The Protocols template argument could not be deduced in one place
  where bond::SelectProtocolAndApply was called. It is now explicitly
  specified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants