[omniORB] omniORB 4.2 : Visual C++ Compiler Warning L4 C4706 "assignment within conditional expression"

Martin Ba 0xcdcdcdcd at gmx.at
Wed Oct 10 08:46:55 BST 2018


Hi!

We use omniORB 4.2.2 with Visual Studio 2017 (15.8).

OmniORB's Source code makes use of the following construct:

     if ((pd_data = v.pd_data)) ...

see: 
https://sourceforge.net/p/omniorb/svn/HEAD/tree/trunk/omniORB/include/omniORB4/poa.h#l645

Even though it already uses double-parens, VC++ isn't satisfied and will 
issue a [C4706 assignment within conditional expression][1] for this line.

C4706 is a Level 4 warning, but we selectively enable it because we 
found it quite useful in other contexts.

Apparently, MS thinks that double-parens are not enough, because they 
explicity call this out in their [docs][1]:

   > The warning will occur even if you
   > double the parentheses around the test condition

The warning can be fixed by changing the line to:

     if ((pd_data = v.pd_data) != 0) ...

Can this be fixed?

cheers,
MArtin



Here's the patch (also attached)
***********************
--- poa.h	2017-09-19 07:32:47.000000000 +0200
+++ poa_mod.h	2018-10-10 09:33:57.000000000 +0200
@@ -640,7 +640,7 @@
      inline Servant_var& operator= (const Servant_var& v) {
        if (v.pd_data != pd_data) {
  	if (pd_data) pd_data->_remove_ref();
-	if ((pd_data = v.pd_data)) pd_data->_add_ref();
+	if ((pd_data = v.pd_data) != 0) pd_data->_add_ref();
        }
        return *this;
      }
***********************


[1] : 
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4706?view=vs-2017

-------------- next part --------------
--- poa.h	2017-09-19 07:32:47.000000000 +0200
+++ poa_mod.h	2018-10-10 09:33:57.000000000 +0200
@@ -640,7 +640,7 @@
     inline Servant_var& operator= (const Servant_var& v) {
       if (v.pd_data != pd_data) {
 	if (pd_data) pd_data->_remove_ref();
-	if ((pd_data = v.pd_data)) pd_data->_add_ref();
+	if ((pd_data = v.pd_data) != 0) pd_data->_add_ref();
       }
       return *this;
     }


More information about the omniORB-list mailing list