[SERVER-17728] typeid(glvalue) warns on clang 3.6 Created: 24/Mar/15  Updated: 08/Jan/24  Resolved: 08/May/15

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 3.0.5, 3.1.3

Type: Bug Priority: Major - P3
Reporter: Mira Carey Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-19486 Can't install MongoDB on El Capitan Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Steps To Reproduce:

#using clang 3.6
scons --mute --cc=clang --cxx=clang++ mongod

Sprint: Platform 3 05/15/15
Participants:

 Description   

Clang 3.6 added a new warning for the use of typeid with glvalue's. I.e. in situations where the argument is an expression and it would have to be evaluated with possible side effects.

Error:

scons: Building targets ...
Compiling build/linux2/x86_64/cc_clang/cxx_clang++/mongo/db/storage/in_memory/in_memory_recovery_unit.o
src/mongo/db/storage/in_memory/in_memory_recovery_unit.cpp:71:70: error: expression with side
      effects will be evaluated despite being used as an operand to 'typeid'
      [-Werror,-Wpotentially-evaluated-expression]
                 LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*change));
                                                                     ^
1 error generated.
Compiling build/linux2/x86_64/cc_clang/cxx_clang++/mongo/db/storage/mmap_v1/dur_recovery_unit.o
src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp:181:69: error: expression with side effects
      will be evaluated despite being used as an operand to 'typeid'
      [-Werror,-Wpotentially-evaluated-expression]
                LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*_changes[i]));

This appeared in:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20141215/120369.html

------------

We have two options moving forward:

Add a suppression:

--- a/SConstruct
+++ b/SConstruct
@@ -1333,6 +1333,9 @@ def doConfigure(myenv):
         # we explicitly disable it here.
         AddToCCFLAGSIfSupported(myenv, "-Wno-missing-braces")
 
+        # Ignore potentially evaluated expressions
+        AddToCCFLAGSIfSupported(myenv, "-Wno-potentially-evaluated-expression")
+
     # Check if we need to disable null-conversion warnings
     if myenv.ToolchainIs('clang'):
         def CheckNullConversion(context):

Change two points in the code to clean this up (the below patch is sufficient for me)

--- a/src/mongo/db/storage/in_memory/in_memory_recovery_unit.cpp
+++ b/src/mongo/db/storage/in_memory/in_memory_recovery_unit.cpp
@@ -67,7 +67,7 @@ namespace mongo {
          try {
              for (Changes::reverse_iterator it = _changes.rbegin(), end = _changes.rend();
                      it != end; ++it) {
-                 ChangePtr change = *it;
+                 Change* change = it->get();
                  LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*change));
                  change->rollback();
              }
 
--- a/src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp
+++ b/src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp
@@ -178,7 +178,8 @@ namespace mongo {
 
         try {
             for (int i = _changes.size() - 1; i >= changesRollbackTo; i--) {
-                LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*_changes[i]));
+                Change* change = _changes[i];
+                LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*change));
                 _changes[i]->rollback();
             }

Basically just do whatever side effecty stuff we need to before the call to typeid.



 Comments   
Comment by Githook User [ 10/Jul/15 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: SERVER-18017 SERVER-17728 Suppres some new clang 3.6 warnings we don't like

(cherry picked from commit 1d9b83f16314cdb1e9da4b5c853870f10abb49df)
Branch: v3.0
https://github.com/mongodb/mongo/commit/9860f961ad50e6cb84bab14721ee4404ce0f4b68

Comment by Andrew Morrow (Inactive) [ 11/Jun/15 ]

amw - We are evaluating your request to have the fix for this issue backported to v3.0. In the meantime, please be aware that it is possible to disable warnings as errors on all recent stable branches by passing the --disable-warnings-as-errors flag to SCons, which should unblock building 3.0 releases on El Capitan.

Comment by Adam Wróbel [ 11/Jun/15 ]

Just tried 3.1.4 on OS X 10.11.b1 and it compiled just fine.

$brew install mongodb --devel
==> Downloading https://fastdl.mongodb.org/src/mongodb-src-r3.1.3.tar.gz
######################################################################## 100.0%
==> Cloning https://github.com/mongodb/mongo-tools.git
Updating /Library/Caches/Homebrew/mongodb--github.com-mongodb-mongo-tools--git
==> Checking out tag r3.1.3
==> ./build.sh
^C
~$brew update
Updated Homebrew from ace0d8f9 to b0d382ba.
==> Updated Formulae
kitchen-sync  lastpass-cli  passenger	  storm		watchman      x265
~$brew install mongodb --devel
==> Downloading https://fastdl.mongodb.org/src/mongodb-src-r3.1.4.tar.gz
######################################################################## 100.0%
==> Cloning https://github.com/mongodb/mongo-tools.git
Updating /Library/Caches/Homebrew/mongodb--github.com-mongodb-mongo-tools--git
==> Checking out tag r3.1.4
==> ./build.sh
==> /usr/local/opt/scons/bin/scons install --prefix=/usr/local/Cellar/mongodb/3.1.4 -j8 --osx-version-min=10.11 CC=/u
==> Caveats
To have launchd start mongodb at login:
    ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
    mongod --config /usr/local/etc/mongod.conf
==> Summary
/usr/local/Cellar/mongodb/3.1.4: 17 files, 167M, built in 5.8 minutes

Comment by Adam Wróbel [ 11/Jun/15 ]

This warning turns out to be compilation error on 10.11 El Capitan.

==> Downloading https://fastdl.mongodb.org/src/mongodb-src-r3.0.3.tar.gz
Already downloaded: /Library/Caches/Homebrew/mongodb-3.0.3.tar.gz
==> Cloning https://github.com/mongodb/mongo-tools.git
Updating /Library/Caches/Homebrew/mongodb--github.com-mongodb-mongo-tools--git
==> Checking out tag r3.0.3
==> ./build.sh
==> /usr/local/opt/scons/bin/scons install --prefix=/usr/local/Cellar/mongodb/3.0.3 -j8 --osx-version-min=10.11 --cc=
            LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*_changes[i]));
                                                                ^
1 error generated.
scons: *** [build/darwin/cc__usr_bin_clang/cxx__usr_bin_clang++/osx-version-min_10.11/mongo/db/storage/mmap_v1/dur_recovery_unit.o] Error 1
scons: building terminated because of errors.

Would be nice if you could backport this into 3.0.4.

Comment by Githook User [ 08/May/15 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: SERVER-18017 SERVER-17728 Suppres some new clang 3.6 warnings we don't like
Branch: master
https://github.com/mongodb/mongo/commit/1d9b83f16314cdb1e9da4b5c853870f10abb49df

Comment by Andrew Morrow (Inactive) [ 08/May/15 ]

mira.carey@mongodb.com knows more of the details, but I believe the issue is that the compiler may or may not evaluate the expression within. So, if you were expecting side effects to happen, they might not. We aren't relying on side effects, and uses of typeid should be exceedingly rare within our codebase.

Comment by Eric Milkie [ 08/May/15 ]

I'm confused about this warning. Is it there because people might think typeid() works like sizeof()?

Generated at Thu Feb 08 03:45:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.