Node: src: squelch unused function warnings in util.h

Created on 13 Oct 2016  路  13Comments  路  Source: nodejs/node

Paper-cut issue. When you include util.h but not util-inl.h, you get the following warnings:

$ echo -e '#include "util.h" \n int main(){}' | \
  g++ -DNODE_WANT_INTERNALS=1 -Ideps/v8/include -Ideps/uv/include -Isrc \
      -Wall -Wextra -Wno-unused-parameter -x c++ -
In file included from <stdin>:1:0:
src/util.h:37:11: warning: inline function 'T* node::Malloc(size_t) [with T = char; size_t = long unsigned int]' used but never defined
 inline T* Malloc(size_t n);
           ^~~~~~
src/util.h:39:11: warning: inline function 'T* node::Calloc(size_t) [with T = char; size_t = long unsigned int]' used but never defined
 inline T* Calloc(size_t n);
           ^~~~~~
src/util.h:28:11: warning: inline function 'T* node::UncheckedMalloc(size_t) [with T = char; size_t = long unsigned int]' used but never defined
 inline T* UncheckedMalloc(size_t n);
           ^~~~~~~~~~~~~~~
src/util.h:30:11: warning: inline function 'T* node::UncheckedCalloc(size_t) [with T = char; size_t = long unsigned int]' used but never defined
 inline T* UncheckedCalloc(size_t n);
           ^~~~~~~~~~~~~~~
C++ lib / src

All 13 comments

I think the compiler needs to know the function to actually inline it. So including the implementation in the header file should solve the problem. util-inl.h has the implementation, whereas util.h does not, hence the warnings. Simply copying the implementation to util.h will work

I'll reference a pull request soon

@bnoordhuis, do I need to make changes to util.h to add implementation or was it just a doubt you wanted to clarify? Because adding implementation would be equivalent to using util.h

I was thinking more of adding a NODE_UNUSED macro that evaluates to __attribute__((unused)) on GCC-compatible compilers (or [[gnu::unused]] or [[maybe_unused]]) and to __declspec(whatever_ms_uses) for Visual Studio.

@Tanuja-Sawant hey, are you going to make a macro? Seems this is a good first contribution I'd like to make, but if you're in progress I will not 'course. Anyway I'd like to see the fix when it's done.

@soleboxy ahaha, seems you're ahead of me :)

@bnoordhuis Hi, Ben. Can you explain for a newbie like me what do you mean by making a macro?

Am I right in assuming it should be like this:

#define NODE_UNUSED(expr) __attribute__((expr))

How is it assumed to be applied in this case and why just not to move inlines like @soleboxy did?

Never mind what I said, I thought the warnings were for the non-templated versions but reading the warnings again, it complains about the non-templated versions using template instances.

@bnoordhuis check out my changes, i responded to your comment. (and offered another solution, wonder what you think about it)
@vitkarpov - sorry man , seemed so interesting to solve this i just went away and did it :)
this is my first cpp PR too :)

No problem! I look forward to see the solution to this issue =)

馃憤 :)

no problem im on it :+1:
@bnoordhuis can you checkout the comment on my last commit change?
i am waiting for your response
thanks :)

@bnoordhuis - hey ben , sorry to bother but could you approve my PR please?
https://github.com/nodejs/node/pull/9115

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Icemic picture Icemic  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments

Brekmister picture Brekmister  路  3Comments

cong88 picture cong88  路  3Comments