>Submitter-Id:  net
>Originator:    Edward Welbourne
>Organization:  
>Confidential:  no
>Synopsis:      __attribute__((deprecated)) broken with inline, ignored with 
>pure virtual, misreported after definition
>Severity:      non-critical
>Priority:      low
>Category:      c++
>Class:         rejects-legal
>Class:         sw-bug
>Release:       3.3.3 (Debian 20040401) (Debian testing/unstable)
>Environment:
System: Linux whorl 2.4.18-1-686-smp #1 SMP Sun Feb 1 04:12:27 MST 2004 i686 
GNU/Linux
Architecture: i686

        
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v 
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib 
--enable-nls --without-included-gettext --enable-__cxa_atexit 
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm 
--enable-java-awt=xlib --enable-objc-gc i486-linux
>Description:
        The __attribute__((deprecated)):
        * cannot be used with inline methods [or: the info needs to say how to 
do so]
          I get a parser error if I put it in the obvious place
        * is ignored when used with a pure virtual method (though I'm pleased 
to see
          it does get inherited - if I change hook's type to Derived* I *do* get
          my warning, even without the attribute overtly on Derived::Virtue)
        * gets a report referencing the *definition* rather than the
          *declaration* (as advertised) if the method is used after its 
definition.

>How-To-Repeat:
        * Save the following to a file named deprecate.cpp; make deprecated
          will then compile it (see comment at end recording output).
          Observe that the use of Virtue gets no warning.
          Observe that second warning for Method() references defn, not decl.
        * Uncomment the attribute on Inline, make deprecated, see parser error.
          It is possible to get round this; declare it with attribute in the
          class body, then have a separate
                inline int Base::Inline() { return 0; }
          after the class body.

class Base {
public:
    virtual int Virtue() __attribute__((deprecated)) = 0;
    int Inline() // __attribute__((deprecated)) // causes parser error
        { return 0; }
    int Method() __attribute__((deprecated)); // declaration
};

class Derived : public Base {
    /* Adding __attribute__((deprecated)) to this makes no difference, but
     * that's sensible enough: */
    int Virtue();
};
int Derived::Virtue() { return Method(); } // warning correctly references 
declaration
int Base::Method() { return 42; } // definition

int main(void) {
    Derived obj;
    Base *hook = &obj;
    return hook->Virtue() // no warning about Virtue !
         + hook->Method(); // warning references definition, not declaration
}

/*
make -k deprecate CXXFLAGS=-fmessage-length=0
g++ -fmessage-length=0    deprecate.cpp   -o deprecate
deprecate.cpp: In member function `virtual int Derived::Virtue()':
deprecate.cpp:14: warning: `Method' is deprecated (declared at deprecate.cpp:6)
deprecate.cpp: In function `int main()':
deprecate.cpp:21: warning: `Method' is deprecated (declared at deprecate.cpp:15)
*/

>Fix:
        Not known.


Reply via email to