Bug #95125 VS2019 fails to compile XCom when compiling with --DEBUG
Submitted: 25 Apr 2019 8:23 Modified: 10 Jul 2019 23:34
Reporter: Georgi Kodinov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0 OS:Windows
Assigned to: CPU Architecture:Any

[25 Apr 2019 8:23] Georgi Kodinov
Description:
VS2019 adds a new debug format /ZI (supports Edit and Continue).
This is not compatible with X-com since it has things like 
case __LINE__: ....

And in this mode __LINE__ is not a constant so the server fails to compile as follows:
C:\Users\gkodinov\dev\mysql-8.0\plugin\group_replication\libmysqlgcs\src\bindings\xcom\xcom\xcom_base.c(1167): error C2051: case expression not constant

How to repeat:
Open mysql-8.0 as a cmake project directory in VS2019 and compile with x64-Debug with Edit and Continue on.

Suggested fix:
diff --git a/cmake/os/Windows.cmake b/cmake/os/Windows.cmake
index 63ad200e238..4195ae95a46 100644
--- a/cmake/os/Windows.cmake
+++ b/cmake/os/Windows.cmake
@@ -140,6 +140,7 @@ IF(MSVC)
       STRING(REPLACE "/MD"  "/MT" "${flag}" "${${flag}}")
     ENDIF()
     STRING(REPLACE "/Zi"  "/Z7" "${flag}" "${${flag}}")
+    STRING(REPLACE "/ZI"  "/Z7" "${flag}" "${${flag}}")
     IF (NOT WIN_DEBUG_NO_INLINE)
       STRING(REPLACE "/Ob0"  "/Ob1" "${flag}" "${${flag}}")
     ENDIF()
[25 Apr 2019 12:20] Ole-hjalmar Kristensen
Just do not use the new debug format /ZI for XCOM

According to cppreference.com, __LINE__ is a constant:

https://en.cppreference.com/w/cpp/preprocessor/replace

__LINE__
expands to the source file line number, an integer constant, can be changed by the #line directive
(macro constant)

I do not know if the standard really specifies that __LINE__ must be a constant, but in any case, changing the assumption that __LINE__ is a constant in xcom is a considerable task, since the automatically generated state machines in XCOM depend on this assumption.
[14 Jun 2019 10:02] Tor Didriksen
Posted by developer:
 
From documentation: The /ZI option is also incompatible with use of the __LINE__ predefined macro; code compiled with /ZI cannot use __LINE__ as a non-type template argument, although 
__LINE__ can be used in macro expansions.

There's a comment section above those substitutions, please extend it to explain why we do not want "/ZI"
[21 Jun 2019 13:50] Georgi Kodinov
Posted by developer:
 
I will extend it as follows:
diff --git a/cmake/os/Windows.cmake b/cmake/os/Windows.cmake
index 9d8b5d7..ca1a436 100644
--- a/cmake/os/Windows.cmake
+++ b/cmake/os/Windows.cmake
@@ -88,6 +88,8 @@ IF(MSVC)
   #     information for use with the debugger. The symbolic debugging
   #     information includes the names and types of variables, as well as
   #     functions and line numbers. No .pdb file is produced by the compiler.
+  #     We can't Use /ZI too since it's causing __LINE__ macros to be non-
+  #     constant on visual studio and hence XCom stops building correctly.
   # - Enable explicit inline:
   #     /Ob1
   #     Expands explicitly inlined functions. By default /Ob0 is used,
@@ -108,6 +110,7 @@ IF(MSVC)
        STRING(REPLACE "/MD"  "/MT" "${flag}" "${${flag}}")
      ENDIF()
      STRING(REPLACE "/Zi"  "/Z7" "${flag}" "${${flag}}")
+     STRING(REPLACE "/ZI"  "/Z7" "${flag}" "${${flag}}")
      IF (NOT WIN_DEBUG_NO_INLINE)
        STRING(REPLACE "/Ob0"  "/Ob1" "${flag}" "${${flag}}")
      ENDIF()
[10 Jul 2019 23:34] Paul DuBois
Posted by developer:
 
Fixed in 5.6.46, 5.7.28, 8.0.18.

VS2019 produced compilation errors with debug compilation selected
due to use of the /ZI flag. Now /Z7 is used instead.