- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I downloaded TBB (tbb21_20080605oss binary for Windows)and started using concurrent_hash_map. However using it triggers warnings by Visual Studio (I am compiling on the highest warning level). I have a habit to compile without a single warning, so I clearly want to iron them out. Some of these can be easily fixed, so it would be great if the fixes made it to some future release :-)
All warnings I am seeing (along with comment on how/whether it's possible to fix them)
tbb21_20080605oss\include\tbb\concurrent_hash_map.h(585) : warning C4512: 'tbb::concurrent_hash_map
- not sure if this is something because of my use of the template, or a general thing; if general, private: node &operator=(const node &); should solve it (I am using concurrent_hash_map with Key = std::wstring and T = std::vector<:DICT::WORDSTAT> and WordStat is a struct of size_t and another struct of 2 std::wstring: WordStat "=" struct { size_t; struct { std::wstring; std::wstring; enum }; };
tbb\concurrent_hash_map.h(730) : warning C4127: conditional expression is constant
tbb\concurrent_hash_map.h(742) : warning C4127: conditional expression is constant
- I don't think this can be solved :-) unless the warning is explicitly disabled locally for the one line with #pragma warning(push,pop) (and #ifdef'ed for _MSC_VER only)
tbb\atomic.h(162) : warning C4244: 'argument' : conversion from 'tbb::internal::atomic_traits::word' to 'char', possible loss of data
- not sure what this means
tbb\concurrent_hash_map.h(578) : warning C4100: 'size' : unreferenced formal parameter
- this is clearly general problem and solvable by commenting size out: (size_t /* size */, node_...)
Boris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Totally agree, presence of warnings usually lends some distrust to a library.
tbbconcurrent_hash_map.h(730) : warning C4127: conditional expression is constant
tbbconcurrent_hash_map.h(742) : warning C4127: conditional expression is constant
- I don't think this can be solved :-) unless the warning is explicitly disabled locally for the one line with #pragma warning(push,pop) (and #ifdef'ed for _MSC_VER only)
First variant:
if ((void)0, constant_flag) ...
Result of operator , () can't be compile-time constant. And '(void)' part is required to shut down gcc about something like 'senseless expression'.
Second variant:
template
T val(T v) {return v;}
if (val(constant_flag)) ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some of these can be easily fixed, so it would be great if the fixes made it to some future release :-)
I submitted discussed fixes for C4127, C4100 and C4512 as 3 patches using the "Make a contribution" link.
C4244 still remains to be tackled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Totally agree, presence of warnings usually lends some distrust to a library.
I can also think of a more practical reason - the warnings I mentioned create clutter and I have to search for really my own warnings (warnings for *my* code) among warnings that don't belong to me. Add to that that some of these 8 warnings are template ones = long as hell, so I then hesitate to go through the warning list at all. :-) Easily solved though by disabling the 4 warnings for the concurrent_hash_map header only.
First variant:
if ((void)0, constant_flag) ...
Result of operator , () can't be compile-time constant. And '(void)' part is required to shut down gcc about something like 'senseless expression'.
- so is the result being computed at runtime?
Second variant:
template
T val(T v) {return v;}
if (val(constant_flag)) ...
- again, is it computed at compile-time?
If yes, I have a strange feeling of changing the resulting binary code that will execute based on compiler warnings that can be solved statically (i.e. with #pragma warning). Does g++ as well produce the "conditional expression constant" warning?
PS.: How do I reply to more than 1 part of a quote? Hitting enter when cursor is at some point of the quote does not split the quote at that place, rather it adds the newline to the quote itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First variant:
if ((void)0, constant_flag) ...
Result of operator , () can't be compile-time constant. And '(void)' part is required to shut down gcc about something like 'senseless expression'.
- so is the result being computed at runtime?
'compile-time constant' vs. 'run-time value' is more like formal thing here. Every sane modern compiler is able to resolve it in compile-time anyway.
template
T val(T v) {return v;}
if (val(constant_flag)) ...
- again, is it computed at compile-time?
Again, every sane modern compiler is able to resolve it in compile-time anyway.
I don't think that it will affect binary code. However, second variant in *debug* build probably will contain additional function call.
Does g++ as well produce the "conditional expression constant" warning?
My g++ 3.4.4 with "-Wall" doesn't produce any warnings wrt constant conditional expressions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
PS.: How do I reply to more than 1 part of a quote? Hitting enter when cursor is at some point of the quote does not split the quote at that place, rather it adds the newline to the quote itself.
PS.: How do I reply to more than 1 part of a quote? Hitting enter when cursor is at some point of the quote does not split the quote at that place, rather it adds the newline to the quote itself.
Then place cursor at bottom, and press Ctrl+V to paste second copy of the post. Now you can add your comments, and delete some parts of quotations as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
tbbconcurrent_hash_map.h(730) : warning C4127: conditional expression is constant
tbbconcurrent_hash_map.h(742) : warning C4127: conditional expression is constant
tbbatomic.h(162) : warning C4244: 'argument' : conversion from 'tbb::internal::atomic_traits::word' to 'char', possible loss of data
tbbconcurrent_hash_map.h(578) : warning C4100: 'size' : unreferenced formal parameter
- this is clearly general problem and solvable by commenting size out: (size_t /* size */, node_...)
For 4512, I think the right way toovercome is to derive the struct node from tbb::no_copy. The warning is there I believe because the mutex variable inside the node is noncopyable already.
For the first of 4127, the way to overcome is probably in declaring grow as non-const automatic variable. I am not sure why it is even declared const now; it won't help any compiler optimization most probably.
The second 4127 is just silly. Yes op_insert is constant; it's the bool template parameter, and it issobecause we want two different implementations to be instantiated from the same code; so dear compiler, instead of issuing a stupid warning, please eliminate the unnecesary code when instantiating the function! Adding 7 lines of code clutter just to workaround this idiocy does not sound right to me. Is this warning issued in debug or in release mode, I wonder?
The 4100 one is reasonable to overcome by avoiding the name for the unusedargument, I agree.
The 4244 in atomic.h would also not be worth the clutter to overcome, but we already have the clutter in place. All you probably need to do is to remove (or comment out) __TBB_x86_64 in the preprocessor condition at line 91.
Could you please check if my proposals work for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Boostmanages to remove alllevel 4 warnings for the MS C++ compiler so I see no reason why TBB couldn't. It's possible to avoid the warnings like this, but it's annoying,
#pragma warning(push,3)
#include "tbb/task.h"
#pragma warning(pop)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
tbbspin_rw_mutex.h(130) : warning C4245: 'argument' : conversion from 'const tbb::spin_rw_mutex_v3::state_t' to 'unsigned int', signed/unsigned mismatch
I did verify that Dmitriy's proposal which includes much less clutter - "if ((void)0, op_insert)" - works for MSVC 9.
All in all, when I combined all the suggestions as you approved them, really the only warning I got was the "silly" instance of C4127. That's a very nice improvement - now I need to disable only 1 warning when including the header, opposed to 4 warnings.
Thanks for your response and looking into this. If I find some easily fixable /W4 stuff in other headers, I will let the forum know (and send patches again).
Boris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, quality is about attention to detail and going the extra mile. If you feel it's finer that lots of TBB usershave to clutter their code with silly work-arounds just to save the TBB team some work then so be it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well to me it's very simple. You delivera high quality product and it shouldn't haveblemishes. If Boost can produce /W4 warning free code, so can you.
It's not adeep philosophical question. It's about costumer perceived quality. If you buy a brand new car you expect the painting to be shining, not covered withsmall scratches.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you're confusing the real issue here.To put it bluntly. You'repassingyour***** on to the consumer of your code. Nobody is interested in why you're doing it, just stop doing it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not adeep philosophical question. It's about costumer perceived quality. If you buy a brand new car you expect the painting to be shining, not covered withsmall scratches.
I've modified my private copy to eliminate the /W4 warnings from VS2005. I still need to run it by VS2008. VS2003 turns out to be impossible to reasonably appease in some cases.
Used car dealers are famous for putting making an internally damaged car shiney. Or evenrepainting a wreck and selling it. A shiney paint job does not mean the car is any good. /W4 is checking the paint.
/W4 can't even check the paint right. The quality issue is with the compiler, not the library. The compiler is issuing unreasonable warnings because it is being sloppy about analysis and written for C programs, not modern templated C++. Of hundreds of /W4 warnings I eliminated, only one said anything reasonable, forthe new class thread_specific_enumerable. I find real issues by code review much more efficiently than wading through these misguided warnings.
Some of the more obnoxious /W4 warnings that I ran into with VS2005.
- += applied to two short operands generates a warning. There is no work-around except to give up on using += or use a pragma.
- Use of compiler-time constants in conditional expressions, particularly in templates.
- Just plain wrong warnings about parameters not being used when in fact they were as arguments to explicit destructor calls.
- A just plain wrong warning about a local variable possibly being used before it is defined.
- A warning about defining a volatile variable but not using it. That's crazy: the whole point of the volatile keyword is to say that there might be hiddenreads/writes for the variable.
- The compiler saying it could not generate operator= for a class, even though I never needed it. This warning goes against Stroustrup's design point that C++ should not prevent potential errors, only actual errors.
- Assignments in the second arm of a || expression. The alternatives ways to write that sort of thing involve gotos, which I consider to be worse.
- A warning about "unreachable code" after a throw expression. There was only whitespace after the throw, so any code generated there was the compiler's fault.
As I said, we'll put an end to the warnings. But it won't improve quality one bit, and clutters the sources with pragmas specific to one vendor's compiler.
- Arch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We might now start waiting for GCC users to come and require us fixing warnings beyond -Wall.Since GCC does not support warning suppression by pragmas, the code clutter will theninclude GCC-specific attributes (hidden by macros, for portability) and warning suppression options in makefiles. The latter will be particularly bad because the suppression is made globally this way.
See the above warning analysis by Arch, then go and say that sentense to your compiler vendor. Whatever I wrote abovewas not for excuse but to educate others that using /W4 in productionis silly and does not add to quality.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree on your general idea, I too use moderntemplatedC++, and I compile my code on 3 compilers right now, and try to keep everyone happy, but anything beyond /w3 on VS2005 or -Wall reduces code quality in my perspective. Most of these warnings are more like moral advice given to young programmers than actual C++ warnings. And the obfuscation required to silence these warnings just ruins themaintainability/literacy/value of code. But that's because of my philosophy for spartan and literate coding.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page