Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7680 Discussions

warning: function was declared but never referenced

Hi, i'm trying to compile my project ( 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
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:
0 Kudos
2 Replies


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*);


class TxThread;

namespace {

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

   template <class CM>
   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.




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