public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35772]  New: GCC allows defining pure virtual functions
@ 2008-03-30 22:18 yuriry at gmail dot com
  2008-03-31  6:42 ` [Bug c++/35772] " herwig at gdsys dot de
  2008-03-31  7:11 ` yuriry at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: yuriry at gmail dot com @ 2008-03-30 22:18 UTC (permalink / raw)
  To: gcc-bugs

GCC compiles the code below without any error:

//----------------------------------
class A {
protected:
  virtual void foo() const = 0;
};

// Defining pure virtual functions should not be allowed.
void A::foo() const 
{
}
//----------------------------------


-- 
           Summary: GCC allows defining pure virtual functions
           Product: gcc
           Version: 4.1.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yuriry at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35772


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/35772] GCC allows defining pure virtual functions
  2008-03-30 22:18 [Bug c++/35772] New: GCC allows defining pure virtual functions yuriry at gmail dot com
@ 2008-03-31  6:42 ` herwig at gdsys dot de
  2008-03-31  7:11 ` yuriry at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: herwig at gdsys dot de @ 2008-03-31  6:42 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]



------- Comment #1 from herwig at gdsys dot de  2008-03-31 06:41 -------
Hi yuri,

I think, this is perfectly correct code and GCC is right in accepting it. First
of all, see "Effective C++" issue 14 about the pure virtual destructor. Then
see here:

http://en.wikipedia.org/wiki/Virtual_function#Abstract_classes_and_pure_virtual_functions

<cite>
Although pure virtual methods typically have no implementation in the class
that declares them, pure virtual methods in C++ are permitted to contain an
implementation in their declaring class, providing fallback or default
behaviour that a derived class can delegate to if appropriate.
</cite>

Regards,
Björn Herwig

(In reply to comment #0)
> GCC compiles the code below without any error:
> 
> //----------------------------------
> class A {
> protected:
>   virtual void foo() const = 0;
> };
> 
> // Defining pure virtual functions should not be allowed.
> void A::foo() const 
> {
> }
> //----------------------------------
> 


-- 

herwig at gdsys dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |herwig at gdsys dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35772


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/35772] GCC allows defining pure virtual functions
  2008-03-30 22:18 [Bug c++/35772] New: GCC allows defining pure virtual functions yuriry at gmail dot com
  2008-03-31  6:42 ` [Bug c++/35772] " herwig at gdsys dot de
@ 2008-03-31  7:11 ` yuriry at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: yuriry at gmail dot com @ 2008-03-31  7:11 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1906 bytes --]



------- Comment #2 from yuriry at gmail dot com  2008-03-31 07:10 -------
Hi Björn,

Thank you for the link and setting me straight.  You are correct,
implementation of a pure virtual function by the class that declares it makes
sense. It is just the class itself remains abstract.

Earlier today I had a problem with dynamic library loading and it disappeared
only after I removed an implementation of a pure virtual method from a
declaring class.  I thought this was a problem, but it looks like I need to
look more at what was happening.

Regards,
Yuri

(In reply to comment #1)
> Hi yuri,
> 
> I think, this is perfectly correct code and GCC is right in accepting it. First
> of all, see "Effective C++" issue 14 about the pure virtual destructor. Then
> see here:
> 
> http://en.wikipedia.org/wiki/Virtual_function#Abstract_classes_and_pure_virtual_functions
> 
> <cite>
> Although pure virtual methods typically have no implementation in the class
> that declares them, pure virtual methods in C++ are permitted to contain an
> implementation in their declaring class, providing fallback or default
> behaviour that a derived class can delegate to if appropriate.
> </cite>
> 
> Regards,
> Björn Herwig
> 
> (In reply to comment #0)
> > GCC compiles the code below without any error:
> > 
> > //----------------------------------
> > class A {
> > protected:
> >   virtual void foo() const = 0;
> > };
> > 
> > // Defining pure virtual functions should not be allowed.
> > void A::foo() const 
> > {
> > }
> > //----------------------------------
> > 
> 


-- 

yuriry at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35772


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-31  7:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-30 22:18 [Bug c++/35772] New: GCC allows defining pure virtual functions yuriry at gmail dot com
2008-03-31  6:42 ` [Bug c++/35772] " herwig at gdsys dot de
2008-03-31  7:11 ` yuriry at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).