Bug #82340 Cannot compile with Clang on Mac OS X 10.10.5
Submitted: 26 Jul 2016 3:12 Modified: 8 Apr 2017 14:27
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:5.7 OS:MacOS
Assigned to: CPU Architecture:Any
Tags: error: cannot take the address of an rvalue of type

[26 Jul 2016 3:12] Davi Arnaut
Description:
Building MySQL from the source fails on on Mac OS X 10.10.5 

How to repeat:
$ make
Scanning dependencies of target client_base
[ 91%] Building CXX object client/base/CMakeFiles/client_base.dir/help_options.cc.o
/Users/darnaut/mysql-server/client/base/help_options.cc:78:39: error: cannot take the address of an rvalue of type
      'std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >'
    (static_cast<std::ostringstream*>(&(
                                      ^
1 error generated.
make[2]: *** [client/base/CMakeFiles/client_base.dir/help_options.cc.o] Error 1
make[1]: *** [client/base/CMakeFiles/client_base.dir/all] Error 2
make: *** [all] Error 2

$ clang --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
darnaut-mn2:~/dds-mysql_t

Suggested fix:
diff --git a/client/base/help_options.cc b/client/base/help_options.cc
index c7443f8..575a555 100644
--- a/client/base/help_options.cc
+++ b/client/base/help_options.cc
@@ -74,10 +74,8 @@ void Mysql::Tools::Base::Options::Help_options::print_usage()

   this->print_version_line();

-  std::string first_year_str=
-    (static_cast<std::ostringstream*>(&(
-    std::ostringstream() << this->m_program->get_first_release_year()))
-    ->str());
+  std::ostringstream oss = std::ostringstream() << this->m_program->get_first_release_year();
+  std::string first_year_str= oss.str();
   string copyright;

   if (first_year_str == COPYRIGHT_NOTICE_CURRENT_YEAR)
[26 Jul 2016 6:05] Davi Arnaut
Pass -std=c++11 flag to compiler to trigger error.

In any case, it's not proper to take reference to a temporary object.
[26 Jul 2016 9:20] Terje Røsten
Hi Davi!

Thanks for your report and fix!
[28 Mar 2017 3:34] Linghua Tseng
Now it's 5.7.17 and the bug is still not fixed.

How come the programmer tried so hard to insist on using -> instead of . and did this way? Please fix it as soon as possible. It's annoyed whenever I tried to install MySQL 5.7 on FreeBSD.
[8 Apr 2017 14:27] Paul DuBois
Posted by developer:
 
Noted in 5.7.19, 8.0.2 changelogs.

MySQL failed to compile under macOS 10.10.5 using Clang.