[MDEV-24116] Build failure on MacOS on compiling the file lock/lock0lock.cc Created: 2020-11-04  Updated: 2020-11-10  Resolved: 2020-11-04

Status: Closed
Project: MariaDB Server
Component/s: Compiling
Affects Version/s: 10.6.0, 10.5
Fix Version/s: 10.5.9, 10.6.0

Type: Bug Priority: Major
Reporter: Dmitry Shulga Assignee: Dmitry Shulga
Resolution: Fixed Votes: 0
Labels: None
Environment:

compiler: Apple clang version 12.0.0 (clang-1200.0.32.21)



 Description   

Attempt to build MariaDB server on mac OS leads to compilation error:

[ 61%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/lock0lock.cc.o
/Users/shulga/projects/mariadb/server-10.5/storage/innobase/lock/lock0lock.cc:5035:23: error: loop variable
'page_id' of type 'const page_id_t' creates a copy from type 'const page_id_t'
[-Werror,-Wrange-loop-analysis]
for (const page_id_t page_id : pages) {
^
/Users/shulga/projects/mariadb/server-10.5/storage/innobase/lock/lock0lock.cc:5035:7: note: use reference
type 'const page_id_t &' to prevent copying
for (const page_id_t page_id : pages) {
^~~~~~~~~~~~~~~~~~~~~~~~~
&
1 error generated.



 Comments   
Comment by Marko Mäkelä [ 2020-11-04 ]

I believe that following the suggestion of the compiler (note) would lead to a performance regression. Please have a look at the definition of page_id_t. Ever since MDEV-17491, the size of the object is 64 bits, which ought to be the same as the size of a pointer or a reference. Even on a 32-bit system, https://github.com/isocpp/CppCoreGuidelines/issues/1514 intentionally leaves this open in the C++ Core Guidelines: the size of the object would be exactly twice the size of a pointer or a reference.

Would the warning go away if you simply removed the const? We do want to copy the 64-bit quantity there. (Also note that before 10.5, page_id_t wrapped two 32-bit members; in 10.5 it is wrapping one 64-bit member.)

Generated at Thu Feb 08 09:27:33 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.