Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

warning: function was declared but never referenced

Ricardo_F_1
Beginner
4,772 Views
Hi, i'm trying to compile my project (https://github.com/riclas/rstm) with ICC but it gives me the following warning, which GCC doesn't:
 
/home/rfilipe/rstm-icc/libstm/algs/norec.cpp(43): warning #177: function "<unnamed>::NOrec_Generic<CM>::commit [with CM=stm::HourglassBackoffCM]" was declared but never referenced
        static TM_FASTCALL void commit(STM_COMMIT_SIG(,));
 
TM_FASTCALL is empty because of an ICC bug reported on https://software.intel.com/en-us/forums/intel-c-compiler/topic/609775.
STM_COMMIT_SIG = TxThread* tx
read and write functions have very similar signatures, declarations and references and don't give this warning.
 
I would like some help to understand if there is something wrong with the code or if it is another ICC bug, since when i run the executable it segfaults here. I have no problem with GCC.
 
Thank you
 
 
relevant lines:
https://github.com/riclas/rstm/blob/master/libstm/algs/norec.cpp#L43
https://github.com/riclas/rstm/blob/master/libstm/algs/algs.hpp#L109
https://github.com/riclas/rstm/blob/master/include/stm/txthread.hpp#L120
https://github.com/riclas/rstm/blob/master/libstm/inst.cpp
0 Kudos
2 Replies
Judith_W_Intel
Employee
4,772 Views

 

This is a warning that does not get emitted by default (you must be using -w1 or greater).

Below is an example of when it would be emitted. The compiler sees that commit() member function is declared/defined inside an unnamed namespace. Thus the only place it can ever be actually referenced (i.e. called) would be from within the translation unit. Is there a call to it from somewhere else in the translation unit? I don't see any but I'm not sure what the macros expand to.

Anyway I doubt this warning has anything to do with a runtime segfault.

sptel15-199> icpc -c -w1 t.cpp
t.cpp(10): warning #177: function "<unnamed>::NOrec_Generic<CM>::commit [with CM=stm::HourglassBackoffCM]" was declared but never referenced
         static void commit(TxThread*);
                     ^

sptel15-200>

class TxThread;

namespace {

   template <class CM>
   struct NOrec_Generic
   {
       static void commit(TxThread*);
   };

   template <class CM>
   void
   NOrec_Generic<CM>::commit(TxThread* tx)
   { }

}

namespace stm {
   struct HourglassBackoffCM {};
   NOrec_Generic< HourglassBackoffCM> n;
   void foo() {
        //n.commit(0); // error disappears if function is referenced (i.e. called)
   }
}

If you still think the warning doesn't make sense please preprocess the file (using the -P option) and post the preprocessed file (it will have a i extension) here.

thanks!

Judy

0 Kudos
Ricardo_F_1
Beginner
4,772 Views

No, it's never called in the translation unit. i can see why the other functions don't give this warning, since they are assigned in the initialize routine. It will be called if set to the stms[].commit function pointer later in the run. I'm compiling with -Wall so it makes sense that it appears. Still, it does not appear with GCC, but then i guess it's a bug on GCC.

And true, it's not connected to my segmentation fault, I have to dig deeper into that one, I just assumed it was since the output was different from GCC, where it doesn't segfault.

Thank you

0 Kudos
Reply