Message ID | ZuILCwY59VmDwBJI@tucnak |
---|---|
State | New |
Headers | show |
Series | c++: Disable deprecated/unavailable diagnostics when creating thunks for methods with such attributes [PR116636] | expand |
On Wed, Sep 11, 2024 at 11:26:35PM +0200, Jakub Jelinek wrote: > Hi! > > On the following testcase, we emit false positive warnings/errors about using > the deprecated or unavailable methods when creating thunks for them, even > when nothing (in the testcase so far) actually used those. > > The following patch temporarily disables that diagnostics when creating > the thunks. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? LGTM. > 2024-09-11 Jakub Jelinek <jakub@redhat.com> > > PR c++/116636 > * method.cc: Include decl.h. > (use_thunk): Temporarily change deprecated_state to > UNAVAILABLE_DEPRECATED_SUPPRESS. > > * g++.dg/warn/deprecated-19.C: New test. > > --- gcc/cp/method.cc.jj 2024-09-06 13:43:37.823301244 +0200 > +++ gcc/cp/method.cc 2024-09-11 12:19:57.420486173 +0200 > @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. > #include "coretypes.h" > #include "target.h" > #include "cp-tree.h" > +#include "decl.h" > #include "stringpool.h" > #include "cgraph.h" > #include "varasm.h" > @@ -283,6 +284,11 @@ use_thunk (tree thunk_fndecl, bool emit_ > /* Thunks are always addressable; they only appear in vtables. */ > TREE_ADDRESSABLE (thunk_fndecl) = 1; > > + /* Don't diagnose deprecated or unavailable functions just because they > + have thunks emitted for them. */ > + auto du = make_temp_override (deprecated_state, > + UNAVAILABLE_DEPRECATED_SUPPRESS); > + > /* Figure out what function is being thunked to. It's referenced in > this translation unit. */ > TREE_ADDRESSABLE (function) = 1; > --- gcc/testsuite/g++.dg/warn/deprecated-19.C.jj 2024-09-11 12:50:25.342634444 +0200 > +++ gcc/testsuite/g++.dg/warn/deprecated-19.C 2024-09-11 13:05:29.210222060 +0200 > @@ -0,0 +1,22 @@ > +// PR c++/116636 > +// { dg-do compile } > +// { dg-options "-pedantic -Wdeprecated" } > + > +struct A { > + virtual int foo () = 0; > +}; > +struct B : virtual A { > + [[deprecated]] int foo () { return 0; } // { dg-message "declared here" } > +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } > +struct C : virtual A { > + [[gnu::unavailable]] int foo () { return 0; } // { dg-message "declared here" } > +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } > + > +void > +bar () > +{ > + B b; > + b.foo (); // { dg-warning "'virtual int B::foo\\\(\\\)' is deprecated" } > + C c; > + c.foo (); // { dg-error "'virtual int C::foo\\\(\\\)' is unavailable" } > +} > > Jakub > Marek
On 9/12/24 10:23 AM, Marek Polacek wrote: > On Wed, Sep 11, 2024 at 11:26:35PM +0200, Jakub Jelinek wrote: >> Hi! >> >> On the following testcase, we emit false positive warnings/errors about using >> the deprecated or unavailable methods when creating thunks for them, even >> when nothing (in the testcase so far) actually used those. >> >> The following patch temporarily disables that diagnostics when creating >> the thunks. >> >> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > LGTM. Yes, OK. >> 2024-09-11 Jakub Jelinek <jakub@redhat.com> >> >> PR c++/116636 >> * method.cc: Include decl.h. >> (use_thunk): Temporarily change deprecated_state to >> UNAVAILABLE_DEPRECATED_SUPPRESS. >> >> * g++.dg/warn/deprecated-19.C: New test. >> >> --- gcc/cp/method.cc.jj 2024-09-06 13:43:37.823301244 +0200 >> +++ gcc/cp/method.cc 2024-09-11 12:19:57.420486173 +0200 >> @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. >> #include "coretypes.h" >> #include "target.h" >> #include "cp-tree.h" >> +#include "decl.h" >> #include "stringpool.h" >> #include "cgraph.h" >> #include "varasm.h" >> @@ -283,6 +284,11 @@ use_thunk (tree thunk_fndecl, bool emit_ >> /* Thunks are always addressable; they only appear in vtables. */ >> TREE_ADDRESSABLE (thunk_fndecl) = 1; >> >> + /* Don't diagnose deprecated or unavailable functions just because they >> + have thunks emitted for them. */ >> + auto du = make_temp_override (deprecated_state, >> + UNAVAILABLE_DEPRECATED_SUPPRESS); >> + >> /* Figure out what function is being thunked to. It's referenced in >> this translation unit. */ >> TREE_ADDRESSABLE (function) = 1; >> --- gcc/testsuite/g++.dg/warn/deprecated-19.C.jj 2024-09-11 12:50:25.342634444 +0200 >> +++ gcc/testsuite/g++.dg/warn/deprecated-19.C 2024-09-11 13:05:29.210222060 +0200 >> @@ -0,0 +1,22 @@ >> +// PR c++/116636 >> +// { dg-do compile } >> +// { dg-options "-pedantic -Wdeprecated" } >> + >> +struct A { >> + virtual int foo () = 0; >> +}; >> +struct B : virtual A { >> + [[deprecated]] int foo () { return 0; } // { dg-message "declared here" } >> +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } >> +struct C : virtual A { >> + [[gnu::unavailable]] int foo () { return 0; } // { dg-message "declared here" } >> +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } >> + >> +void >> +bar () >> +{ >> + B b; >> + b.foo (); // { dg-warning "'virtual int B::foo\\\(\\\)' is deprecated" } >> + C c; >> + c.foo (); // { dg-error "'virtual int C::foo\\\(\\\)' is unavailable" } >> +} >> >> Jakub >> > > Marek >
--- gcc/cp/method.cc.jj 2024-09-06 13:43:37.823301244 +0200 +++ gcc/cp/method.cc 2024-09-11 12:19:57.420486173 +0200 @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. #include "coretypes.h" #include "target.h" #include "cp-tree.h" +#include "decl.h" #include "stringpool.h" #include "cgraph.h" #include "varasm.h" @@ -283,6 +284,11 @@ use_thunk (tree thunk_fndecl, bool emit_ /* Thunks are always addressable; they only appear in vtables. */ TREE_ADDRESSABLE (thunk_fndecl) = 1; + /* Don't diagnose deprecated or unavailable functions just because they + have thunks emitted for them. */ + auto du = make_temp_override (deprecated_state, + UNAVAILABLE_DEPRECATED_SUPPRESS); + /* Figure out what function is being thunked to. It's referenced in this translation unit. */ TREE_ADDRESSABLE (function) = 1; --- gcc/testsuite/g++.dg/warn/deprecated-19.C.jj 2024-09-11 12:50:25.342634444 +0200 +++ gcc/testsuite/g++.dg/warn/deprecated-19.C 2024-09-11 13:05:29.210222060 +0200 @@ -0,0 +1,22 @@ +// PR c++/116636 +// { dg-do compile } +// { dg-options "-pedantic -Wdeprecated" } + +struct A { + virtual int foo () = 0; +}; +struct B : virtual A { + [[deprecated]] int foo () { return 0; } // { dg-message "declared here" } +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } +struct C : virtual A { + [[gnu::unavailable]] int foo () { return 0; } // { dg-message "declared here" } +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } + +void +bar () +{ + B b; + b.foo (); // { dg-warning "'virtual int B::foo\\\(\\\)' is deprecated" } + C c; + c.foo (); // { dg-error "'virtual int C::foo\\\(\\\)' is unavailable" } +}