This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/5086: -Wctor-dtor-privacy gives spurious warnings



>Number:         5086
>Category:       c++
>Synopsis:       -Wctor-dtor-privacy gives spurious warnings
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 11 21:16:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Bill Clarke
>Release:        3.0.2
>Organization:
>Environment:
sparc-sun-solaris2.8
>Description:
the documentation for -Wctor-dtor-privacy says:
"`-Wctor-dtor-privacy (C++ only)'
     Warn when a class seems unusable, because all the constructors or
     destructors in a class are private and the class has no friends or
     public static member functions."

however, -Wctor-dtor-privacy gives spurious warnings when the first public member function is not static.  see the attached file (test-ctor-dtor-privacy.cc) in which the class ExhibitsCtorDtorPrivacyBug produces the "warning" but class DoesNotExhibitBug does not.

-Wctor-dtor-privacy is included in -Wall, and so is worth fixing (imo).  
>How-To-Repeat:
compile attachment (test-ctor-dtor-privacy.cc, has no includes) with:
$ g++ -Wctor-dtor-privacy -c test-ctor-dtor-privacy.cc
test-ctor-dtor-privacy.cc:1: warning: `class ExhibitsCtorDtorPrivacyBug' only 
   defines private constructors and has no friends
$ 
>Fix:
the workaround is to put a static member function as the first public member.
an alternative fix is to change the documentation (-:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="test-ctor-dtor-privacy.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test-ctor-dtor-privacy.cc"

Y2xhc3MgRXhoaWJpdHNDdG9yRHRvclByaXZhY3lCdWcgewpwcml2YXRlOgogIEV4aGliaXRzQ3Rv
ckR0b3JQcml2YWN5QnVnKCk7CgogIC8vIGRpc2FsbG93IGNvcHk6CiAgRXhoaWJpdHNDdG9yRHRv
clByaXZhY3lCdWcoY29uc3QgRXhoaWJpdHNDdG9yRHRvclByaXZhY3lCdWcmKTsKICBFeGhpYml0
c0N0b3JEdG9yUHJpdmFjeUJ1ZyYgb3BlcmF0b3I9KGNvbnN0IEV4aGliaXRzQ3RvckR0b3JQcml2
YWN5QnVnJik7CnB1YmxpYzoKICB2b2lkIHRoaXNfY2F1c2VzX3RoZV9idWcoKTsKICBzdGF0aWMg
dm9pZCBkb19zb21ldGhpbmcoKTsKfTsKCmNsYXNzIERvZXNOb3RFeGhpYml0QnVnIHsKcHJpdmF0
ZToKICBEb2VzTm90RXhoaWJpdEJ1ZygpOwoKICAvLyBkaXNhbGxvdyBjb3B5OgogIERvZXNOb3RF
eGhpYml0QnVnKGNvbnN0IERvZXNOb3RFeGhpYml0QnVnJik7CiAgRG9lc05vdEV4aGliaXRCdWcm
IG9wZXJhdG9yPShjb25zdCBEb2VzTm90RXhoaWJpdEJ1ZyYpOwpwdWJsaWM6CiAgc3RhdGljIHZv
aWQgZG9fc29tZXRoaW5nKCk7CiAgdm9pZCB0aGlzX2lzX3RoZV93b3JrYXJvdW5kKCk7Cn07Cg==


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]