This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: mutex failing (stupid C++!)
- From: "Kaz Kylheku" <kaz at zeugmasystems dot com>
- To: "skaller" <skaller at users dot sourceforge dot net>, <gcc-help at gcc dot gnu dot org>
- Date: Wed, 31 Oct 2007 14:09:22 -0700
- Subject: RE: mutex failing (stupid C++!)
gcc-help-owner@gcc.gnu.org wrote:
> Arggg .. C++ is such a mess.. look at this and spot the bug:
>
> {
> flx_mutex_locker_t (*ehd->spawner_lock);
> fprintf(stderr,"Thread %p acquired mutex\n", pthread_self());
> *ehd->spawner_flag=true; ehd->spawner_cond->broadcast();
> fprintf(stderr,"Thread %p releasing mutex\n", pthread_self()); }
>
> This baffled me for 3 days now. The code is legal, it just
> doesn't do what I expected. The fix is ONE CHARACTER.
This should be diagnosed by -Wunused, IMHO. You are calling a
constructor, but ignoring the return value.
Let's look at it this way: if you write:
2 + 2;
into the program, -Wunused will give you a diagnostic. But if you
construct an object and ignore the result, you don't get a diagnostic.
What's the difference? The expression 2 + 2 is a constructor for 4.