From: Fariborz Jahanian Date: Thu, 6 Oct 2011 23:47:58 +0000 (+0000) Subject: objc: Improve on diagnostic when atomic proeprty is synthesized X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d65f6965d215f4cb2eb0738ee1b9024e5ab5bba;p=clang objc: Improve on diagnostic when atomic proeprty is synthesized on one accessor and user-provide with another. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141343 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 411d49c912..28e0fab4e3 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -498,9 +498,11 @@ def warn_objc_property_retain_of_block : Warning< "retain'ed block property does not copy the block " "- use copy attribute instead">, InGroup; def warn_atomic_property_rule : Warning< - "writable atomic property %0 cannot pair a synthesized setter/getter " - "with a user defined setter/getter">, + "writable atomic property %0 cannot pair a synthesized %select{getter|setter}1 " + "with a user defined %select{getter|setter}2">, InGroup>; +def note_atomic_property_fixup_suggest : Note<"setter and getter must both be " + "synthesized, or both be user defined,or the property must be nonatomic">; def warn_atomic_property_nontrivial_assign_op : Warning< "atomic property of type %0 synthesizing setter using non-trivial assignment" "operator">, InGroup>; diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 5a54f57580..13ccf82cf4 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1432,7 +1432,9 @@ Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl, (GetterMethod ? GetterMethod->getLocation() : SetterMethod->getLocation()); Diag(MethodLoc, diag::warn_atomic_property_rule) - << Property->getIdentifier(); + << Property->getIdentifier() << (GetterMethod != 0) + << (SetterMethod != 0); + Diag(MethodLoc, diag::note_atomic_property_fixup_suggest); Diag(Property->getLocation(), diag::note_property_declare); } } diff --git a/test/SemaObjC/atomoic-property-synnthesis-rules.m b/test/SemaObjC/atomoic-property-synnthesis-rules.m index af790e3159..2061a779dc 100644 --- a/test/SemaObjC/atomoic-property-synnthesis-rules.m +++ b/test/SemaObjC/atomoic-property-synnthesis-rules.m @@ -240,8 +240,10 @@ GET(GetSet) SET(GetSet) -GET(Get) // expected-warning {{writable atomic property 'Get' cannot pair a synthesized setter/getter with a user defined setter/getter}} -SET(Set) // expected-warning {{writable atomic property 'Set' cannot pair a synthesized setter/getter with a user defined setter/getter}} +GET(Get) // expected-warning {{writable atomic property 'Get' cannot pair a synthesized setter with a user defined getter}} \ + // expected-note {{setter and getter must both be synthesized}} +SET(Set) // expected-warning {{writable atomic property 'Set' cannot pair a synthesized getter with a user defined setter}} \ + // expected-note {{setter and getter must both be synthesized}} GET(GetSet_Nonatomic) SET(GetSet_Nonatomic) GET(Get_Nonatomic) @@ -258,8 +260,10 @@ SET(Set_Nonatomic_ReadOnly) GET(GetSet_ReadWriteInExt) SET(GetSet_ReadWriteInExt) -GET(Get_ReadWriteInExt) // expected-warning {{writable atomic property 'Get_ReadWriteInExt' cannot pair a synthesized setter/getter with a user defined setter/getter}} -SET(Set_ReadWriteInExt) // expected-warning {{writable atomic property 'Set_ReadWriteInExt' cannot pair a synthesized setter/getter with a user defined setter/getter}} +GET(Get_ReadWriteInExt) // expected-warning {{writable atomic property 'Get_ReadWriteInExt' cannot pair a synthesized setter with a user defined getter}} \ + // expected-note {{setter and getter must both be synthesized}} +SET(Set_ReadWriteInExt) // expected-warning {{writable atomic property 'Set_ReadWriteInExt' cannot pair a synthesized getter with a user defined setter}} \ + // expected-note {{setter and getter must both be synthesized}} GET(GetSet_Nonatomic_ReadWriteInExt) SET(GetSet_Nonatomic_ReadWriteInExt) GET(Get_Nonatomic_ReadWriteInExt) @@ -268,8 +272,10 @@ SET(Set_Nonatomic_ReadWriteInExt) GET(GetSet_LateSynthesize) SET(GetSet_LateSynthesize) -GET(Get_LateSynthesize) // expected-warning {{writable atomic property 'Get_LateSynthesize' cannot pair a synthesized setter/getter with a user defined setter/getter}} -SET(Set_LateSynthesize) // expected-warning {{writable atomic property 'Set_LateSynthesize' cannot pair a synthesized setter/getter with a user defined setter/getter}} +GET(Get_LateSynthesize) // expected-warning {{writable atomic property 'Get_LateSynthesize' cannot pair a synthesized setter with a user defined getter}} \ + // expected-note {{setter and getter must both be synthesized}} +SET(Set_LateSynthesize) // expected-warning {{writable atomic property 'Set_LateSynthesize' cannot pair a synthesized getter with a user defined setter}} \ + // expected-note {{setter and getter must both be synthesized}} GET(GetSet_Nonatomic_LateSynthesize) SET(GetSet_Nonatomic_LateSynthesize) GET(Get_Nonatomic_LateSynthesize) @@ -286,8 +292,10 @@ SET(Set_Nonatomic_ReadOnly_LateSynthesize) GET(GetSet_ReadWriteInExt_LateSynthesize) SET(GetSet_ReadWriteInExt_LateSynthesize) -GET(Get_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Get_ReadWriteInExt_LateSynthesize' cannot pair a synthesized setter/getter with a user defined setter/getter}} -SET(Set_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Set_ReadWriteInExt_LateSynthesize' cannot pair a synthesized setter/getter with a user defined setter/getter}} +GET(Get_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Get_ReadWriteInExt_LateSynthesize' cannot pair a synthesized setter with a user defined getter}} \ + // expected-note {{setter and getter must both be synthesized}} +SET(Set_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Set_ReadWriteInExt_LateSynthesize' cannot pair a synthesized getter with a user defined setter}} \ + // expected-note {{setter and getter must both be synthesized}} GET(GetSet_Nonatomic_ReadWriteInExt_LateSynthesize) SET(GetSet_Nonatomic_ReadWriteInExt_LateSynthesize) GET(Get_Nonatomic_ReadWriteInExt_LateSynthesize)