🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #805

Re: ensuring CriticalSections are release..

#805
From: Dennis Jones
Date: Mon, 14 Jan 2008 22:36
61 lines
3133 bytes
"Clayton Arends" <nospam_claytonarends@hotmail.com> wrote in message 
news:478bba5f$1@newsgroups.borland.com...
> "Clayton Arends" <nospam_claytonarends@hotmail.com> wrote in message 
> news:478bac9a$1@newsgroups.borland.com...
>
>> I have one itty bitty problem with using this approach.  I haven't looked 
>> closely enough yet to see why it's happening.

I believe the warning is correct.  It is the result of scopegaurd creating 
an RAII object whose destructor is invoked when it goes out of scope, but is 
not used otherwise.  It is no different, say, than:

void test()
{
    int i=1;  // assigned a value, but never used -- may generate W8004
}


> Well, I dug a little deeper.  If I use ScopeGuardImpl1 (for example) 
> directly rather than using the MakeGuard() function then I can avoid the 
> warning:
>
>  ScopeGuardImpl1<void (*)(char*), char*> auto_a =
>    ScopeGuardImpl1<void (*)(char*), char*>::MakeGuard(&DeleteIt, a);

That's interesting, because I would actually *expect* the same warning 
there, because you are assigning a value to auto_a, but never using it.

[
Aside: the & (address of) operator is not needed:

    ScopeGuardImpl1<void (*)(char*), char*>::MakeGuard(DeleteIt, a);
]

Also, if you use MakeGuard() and then have to dismiss the guard later, that 
constitutes usage that would eliminate the warning.  For example:

void test()
{
    char* c = new char;
    ScopeGuard DeleteGuard = MakeGuard( DeleteIt, c );  // no warning 
because DeleteGuard gets used (via Dismiss()) later
    delete c;
    DeleteGuard.Dismiss();
}

Although using ScopeGuard is not perfectly clean with regard to warnings, 
that particular warning is, IMO, extremely minor, especially when compared 
to the benefit that ScopeGuard provides.  If you really dislike the warning, 
you can always use "pragma warn" to get rid of it:

#pragma warn -8004
void test()
{
    char* c = new char;
    ON_BLOCK_EXIT( DeleteIt, c );
}
#pragma warn .8004

- Dennis 
Technical Details
Message-ID: <478be3e4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed10.multikabel.net!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <478a96e3@newsgroups.borland.com> <478b0076$1@newsgroups.borland.com> <478bac9a$1@newsgroups.borland.com> <478bba5f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,266d339b0fd4ba38
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Dennis Jones" <nospam@nospam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <478a96e3@newsgroups.borland.com> <478b0076$1@newsgroups.borland.com> <478bac9a$1@newsgroups.borland.com> <478bba5f$1@newsgroups.borland.com>
Subject: Re: ensuring CriticalSections are release..
Date: Mon, 14 Jan 2008 14:36:22 -0800
Lines: 63
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 71.245.109.58
Message-ID: <478be3e4$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1200350180 71.245.109.58 (14 Jan 2008 14:36:20 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed10.multikabel.net!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail