Bug #85157 C++ language conformance (MSVC /permissive-)
Submitted: 23 Feb 2017 18:39 Modified: 26 Apr 2017 18:52
Reporter: Philip Christensen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version: OS:Windows
Assigned to: CPU Architecture:Any

[23 Feb 2017 18:39] Philip Christensen
Description:
We (the Microsoft C++ team) use the MySQL project as part of our "Real world code" tests.  I noticed a few issues in windows specific code when building MySQL with the MSVC compiler in its conformance mode (/permissive-).  For more information on /permissive- see our blog https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/.

There are three types of issues that affect your project.

1) Use of qualified names in member declarations

    struct A {
        void A::f() { } // error C4596: illegal qualified name in member declaration
                        // remove redundant 'A::' to fix
    };

2) String literal type conversion
  This is also enforced when you use the /Zc:strictString compiler flag.

    char * str = "string"; // String literal loses 'const'
	                       // either change to 'const char*' or cast literal to 'char*'

3) Do not allow skipping an initializer with a goto

    void func(bool b)
    {
        if(b) goto END;
  
        int value = 0; //error C2362: initialization of 'value' is skipped by 'goto END'
  
        //... value used here
  
    END:
        return;
    }

How to repeat:
For the strict strings issue you can build with /Zc:strictStrings added to your build flags.  To verify the other issues you will need to install the latest MSVC compiler and add /permissive- to the build flags.

A quick-and-dirty way to add it for easy verification is by setting the _CL_ environment variable.

set _CL_=/Zc:strictStrings

Suggested fix:
See the blog post mentioned earlier for more information of potential fixes

1) qualified names

Remove the extra 'Handshake::' from packet_processing_loop()
libmysql/authentication_win/handshake.h(103)

Remove the extra My_xp_cond_win:: from get_milliseconds()
rapid/plugin/group_replication/libmysqlgcs/include/mysql/gcs/xplatform/my_xp_cond.h (126)
sql/mysqld.cc (825,7110)

A string literal is passed as the second argument of got_service_option, so it should be made into a const char*
sql/nt_servc.h (64) 
sql/nt_servc.cc (511)

2) Strict string literals
shared_memory_base_name should be changed to be a 'const char*', or a const cast should be added when it is initialized by default_shared_memory_base_name.
See client/MySQL_secure_installation.cc(38)

3) skipping initialization
The initialization being skipped is 'channel_info' in sql/conn_handler/shared_memory_connection.cc (309).  You can limit the scope of the value by adding an extra {}.  See the blog for examples.
[24 Feb 2017 1:03] MySQL Verification Team
Thank you for the bug report and contribution. Thanks in advance.

In order to submit contributions you must first sign the Oracle
Contribution Agreement (OCA). For additional information please check
http://www.oracle.com/technetwork/community/oca-486395.html

If you have any questions, please contact the MySQL community team at
http://www.mysql.com/about/contact/?topic=community
[24 Feb 2017 16:28] Peter Laursen
I don't understand that this requires signing the OCA. It is simple code cleanup/refactoring in order to comform with standards. 

Then the C++ committee would also need to sign the OCA for Oracle to use C++, I think! :-)

-- Peter
-- not a MySQL/Oracle person
[7 Mar 2017 17:44] Paul DuBois
Posted by developer:
 
Fixed in 8.0.2.

Code cleanup. No changelog entry needed.
[26 Apr 2017 18:52] Philip Christensen
I am not sure how version 8.0.2 relates to the released version of SQL.  When should I expect this change to make it to the version of the source code on GitHub?  (I currently still see the issue there)
[4 May 2017 7:44] Ma Phoebehui
Where I can get the source version 8.0.2
[25 Oct 2018 19:48] Omer Barnir
Also, further information on the MySQL 8.0 C++ code improvements:
https://mysqlserverteam.com/mysql-8-0-source-code-improvements/