On Tue, Jul 16, 2013 at 2:17 PM, Lubos Lunak <[email protected]> wrote:
> On Tuesday 16 of July 2013, Richard Smith wrote: > > On Tue, Jul 16, 2013 at 12:50 PM, Lubos Lunak <[email protected]> wrote: > > > On Tuesday 16 of July 2013, Richard Smith wrote: > > > > Consider: > > > > > > > > { > > > > my_lock(my_mutex); // A > > > > my_lock ml(my_mutex); // B > > > > my_string("foo"); // C > > > > my_string ms("foo"); // D > > > > } > > > > > > > > We never warn for a class that is in category (1). my_lock would be > in > > > > category (2), so we warn on A but not B. my_string would be in > category > > > > (3), so we warn on both C and D. > > > > > > > > Which of these does the warn_unused attribute model? > > > > > > It doesn't model anything. It prevents disabling of the > unused-variable > > > warning for whatever type that has the attribute. > > > > So which of the above behaviors do you get? (Or do you get something > else?) > > I think you are talking about something slightly different. This is about > the > (-W)unused-variable warning. So A and C obviously don't apply. B and D will > cause the warning if the relevant variable has at most trivial ctor/dtor > called (before my patch), or has at most even non-trivial ctor/dtor called > but also has the attribute set (added by the patch). That's all. OK, thanks. I think that this means the semantics of your attribute correspond to my category (3) (that is, it means that the ctor and dtor have no external side effects). Some trivial pedantry below, but otherwise LGTM. --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -749,6 +749,10 @@ def VecReturn : InheritableAttr { let Subjects = [CXXRecord]; } +def WarnUnused : InheritableAttr { + let Spellings = [GNU<"warn_unused">, CXX11<"gnu", "warn_unused">]; +} Please add let Subjects = [Record]; to this. Subjects has no effect yet, but we're in the process of switching to automatically generating the "does this attribute appertain to this entity" code. --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2669,6 +2669,17 @@ static void handleSentinelAttr(Sema &S, Decl *D, const AttributeList &Attr) { Attr.getAttributeSpellingListIndex())); } +static void handleWarnUnusedAttr(Sema &S, Decl *D, const AttributeList &Attr) { + // check the attribute arguments. Please capitalize this comment. Thanks!
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
