Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-17728

typeid(glvalue) warns on clang 3.6

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.5, 3.1.3
    • Component/s: Internal Code
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Completed:
    • Steps To Reproduce:
      Hide

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

      Show
      #using clang 3.6 scons --mute --cc=clang --cxx=clang++ mongod
    • Sprint:
      Platform 3 05/15/15

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: