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

Bond build failed with error C5208 in MSVC #1027

Closed
Cheney-W opened this issue Mar 13, 2020 · 9 comments · Fixed by #1041
Closed

Bond build failed with error C5208 in MSVC #1027

Cheney-W opened this issue Mar 13, 2020 · 9 comments · Fixed by #1041
Labels

Comments

@Cheney-W
Copy link

Cheney-W commented Mar 13, 2020

Hello, I'm a member of Microsoft VCPKG, when I built this port in an internal version of Visual Studio, it failed with following errors:
cpp\generated\bond\core\bond_reflection.h(36): error C5208: unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes
This error is caused by our implementation of [C ++ 20] Implement P1766R1, this change introduces a new warning/error when compiling code that looks like this:

typedef struct {
  int a;
  int b = 0;
  //    ^ non-static data member initializer not allowed
  void f() { } // not allowed
  static void sf() { } // not allowed
  struct U {
      // The above apply to nested classes:
      int b = 0;
      //    ^ non-static data member initializer not allowed
      void f() { } // not allowed
      static void sf() { } // not allowed
      U() { } // not allowed
      ~U() { } // not allowed
  };
} S;

In order to fix patterns like this the unnamed class must be given a name explicitly:

typedef struct **S_** {
  int a;
  int b = 0;
  //    ^ non-static data member initializer not allowed
  void f() { } // not allowed
  static void sf() { } // not allowed
  struct U {
      // The above apply to nested classes:
      int b = 0;
      //    ^ non-static data member initializer not allowed
      void f() { } // not allowed
      static void sf() { } // not allowed
      U() { } // not allowed
      ~U() { } // not allowed
  };
} **S**;

In the bond_reflection.h file, there are 30 structures like this that will trigger error C5208:

typedef struct : ::bond::reflection::FieldTemplate<
                8189,
                ::bond::reflection::optional_field_modifier,
                SerializableExceptionBase,
                std::string,
                &SerializableExceptionBase::message,
                &s_message_metadata
            > {}  message;

After testing, adding the name to the structure can fix this problem:
typedef struct **message_**: ::bond::reflection::FieldTemplate<

Since this file is an auto-generated file by the tool: Bond Compiler 0.11.0.3, and I'm not very clear about its generation rules, so could you please fix this problem? If you need any information, please contact me directly. Thanks in advance.

@chwarr
Copy link
Member

chwarr commented Mar 14, 2020

Some background details: the anonymous struct was introduced in 906272b (see also PR #374) to reduce symbol size. IIRC, this was done to reduce compilation times and PDB sizes on Windows.

@chwarr chwarr added the bug label Mar 14, 2020
@cdacamar
Copy link

Hi chwarr,

The code in that change is no longer considered well-formed code. A unnamed class with typedef name for linkage purposes is not allowed to have certain properties, see [dcl.typedef]/10 for more info. The paper which introduced that change was a DR meaning that it will apply to all language modes.

There are a couple of ways you can go about changing the code with the most obvious fix being apply a name to these types. In fact, a name would further shorten the typenames in the PDB because the entry for the unnamed typedef symbol will be prefixed with extra information which forces it to be unique.

Another, arguably easier, solution is to remove the typedef altogether and make the declaration a struct with the old typedef name.

Let me know if you have any further questions about this!

Cameron DaCamara, Visual C++ Compiler Team.

@chwarr
Copy link
Member

chwarr commented Apr 29, 2020

FYI, @Cheney-W and @cdacamar: we believe that this has been fixed in master as of commit f1cb707134.

Thanks to @BertusGreeff for contributing the fix, and thank you both for the report and your help crafting the fix!

@215020267
Copy link

215020267 commented May 11, 2020

@chwarr and @BertusGreeff, thanks for fixing this issue! The MSVC team testing the latest source code under /std:c++latest mode, other auto-generated files still triggered this issue, see the build.log for details, could you help fix this issue?

error:
F:\gitP\microsoft\bond\build_amd64\cpp\test\compat\grpc\Release\pingpong_grpc.h(43,28): error C7626: unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes
F:\gitP\microsoft\bond\build_amd64\examples\cpp\grpc\scalar\Release\scalar_grpc.h(43,28): error C7626: unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes

@chwarr chwarr reopened this May 16, 2020
chwarr added a commit to chwarr/bond that referenced this issue May 16, 2020
As of C++20, it is malformed to have an unnamed class used in typedef with a
base class. In the generated reflection code for a service, we were using the
following construct to create a reflectable entry for each field in a
struct.

```
struct service {
    typedef struct /* no name */ : ::bond::reflection::MethodTemplate<...> {} method_name;
}
```

Now, instead of using an unnamed class, we generate a named class and refer
to that:

```
struct service {
    typedef struct method_name_type : ::bond::reflection::MethodTemplate<...> {} field_name;
}
```

This commit is very similar in spirit to f1cb707. See that commit for
even more details about what's going on.

Also adds a test that compiles a service that has method names that
conflict with the names in `MethodTemplate`. The gRPC++ unit test CMake
now has a single library with the compiled generated code.

Fixes microsoft#1027
@chwarr
Copy link
Member

chwarr commented May 16, 2020

I think I have a fix for this problem in the generated _grpc.h code. PR #1041.

chwarr added a commit that referenced this issue May 18, 2020
As of C++20, it is malformed to have an unnamed class used in typedef with a
base class. In the generated reflection code for a service, we were using the
following construct to create a reflectable entry for each field in a
struct.

```
struct service {
    typedef struct /* no name */ : ::bond::reflection::MethodTemplate<...> {} method_name;
}
```

Now, instead of using an unnamed class, we generate a named class and refer
to that:

```
struct service {
    typedef struct method_name_type : ::bond::reflection::MethodTemplate<...> {} field_name;
}
```

This commit is very similar in spirit to f1cb707. See that commit for
even more details about what's going on.

Also adds a test that compiles a service that has method names that
conflict with the names in `MethodTemplate`. The gRPC++ unit test CMake
now has a single library with the compiled generated code.

Fixes #1027
@chwarr
Copy link
Member

chwarr commented May 18, 2020

@215020267, I think I've fixed this in the _grpc.h headers in commit 3454728 that I just merged into master.

@jthelin
Copy link

jthelin commented May 20, 2020

Any plans for a maintenance release containing these changes?
Upgrading to the latest Visual Studio 2019 v16.6 just released this week has turned on more C++20 functionality in MSVC, and which is now causing all our bond projects to fail to build because of this issue.

@jthelin jthelin mentioned this issue May 20, 2020
@mdslack
Copy link

mdslack commented May 23, 2020

Any plans for a maintenance release containing these changes?
Upgrading to the latest Visual Studio 2019 v16.6 just released this week has turned on more C++20 functionality in MSVC, and which is now causing all our bond projects to fail to build because of this issue.

I'm also running into the same problem.

@chwarr
Copy link
Member

chwarr commented May 27, 2020

@mdslack & @jthelin: the 9.0.0 release is live now. NuGet.org has the packages too.

chengwei45254 pushed a commit to chengwei45254/IPC.Bond that referenced this issue Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants