diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-03-08 22:25:36 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-03-08 22:25:36 +0000 |
commit | a0a86bed7143da94aaf4b26c4f24fd7af6442463 (patch) | |
tree | 91b1080d0898a2aaf642600172180cfc069b0663 /clang/test/SemaObjCXX/arc-nsconsumed-errors.mm | |
parent | d831d955f68cffbfa7a3a9027535f5f994655b77 (diff) | |
download | bcm5719-llvm-a0a86bed7143da94aaf4b26c4f24fd7af6442463.tar.gz bcm5719-llvm-a0a86bed7143da94aaf4b26c4f24fd7af6442463.zip |
Sema: Preserve attributes on parameters in instantiated function templates.
This was causing correctness issues for ARC and the static analyzer when a
function template has "consumed" Objective-C object parameters (i.e.
parameters that will be released by the function before returning).
The fix is threefold:
(1) Actually copy over the attributes from old ParmVarDecls to new ones.
(2) Have Sema::BuildFunctionType only work for building FunctionProtoTypes,
which it was doing anyway. This allows us to pass an ExtProtoInfo
instead of a plain ExtInfo and several flags.
(3) Drop param attributes as part of StripImplicitInstantiation, which is
used when an implicit instantiation is followed by an explicit one.
<rdar://problem/12685622>
llvm-svn: 176728
Diffstat (limited to 'clang/test/SemaObjCXX/arc-nsconsumed-errors.mm')
-rw-r--r-- | clang/test/SemaObjCXX/arc-nsconsumed-errors.mm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/test/SemaObjCXX/arc-nsconsumed-errors.mm b/clang/test/SemaObjCXX/arc-nsconsumed-errors.mm index 93f5d999675..10ae10d0498 100644 --- a/clang/test/SemaObjCXX/arc-nsconsumed-errors.mm +++ b/clang/test/SemaObjCXX/arc-nsconsumed-errors.mm @@ -18,3 +18,35 @@ blk1 b2 = ^void (id, __attribute((ns_consumed)) id){}; // expected-error {{canno blk1 c3 = ^void (__attribute((ns_consumed)) id, __attribute((ns_consumed)) id){}; blk1 d4 = ^void (id, id) {}; // expected-error {{cannot initialize a variable of type '__strong blk1'}} + + +typedef void (*releaser_t)(__attribute__((ns_consumed)) id); + +void normalFunction(id); +releaser_t r1 = normalFunction; // expected-error {{cannot initialize a variable of type 'releaser_t'}} + +void releaser(__attribute__((ns_consumed)) id); +releaser_t r2 = releaser; // no-warning + +template <typename T> +void templateFunction(T) {} // expected-note {{candidate function}} +releaser_t r3 = templateFunction<id>; // expected-error {{address of overloaded function 'templateFunction' does not match required type 'void (id)'}} + +template <typename T> +void templateReleaser(__attribute__((ns_consumed)) T) {} +releaser_t r4 = templateReleaser<id>; // no-warning + + +@class AntiRelease, ExplicitAntiRelease, ProRelease; + +template<> +void templateFunction(__attribute__((ns_consumed)) AntiRelease *); // expected-error {{no function template matches function template specialization 'templateFunction'}} + +template<> +void templateReleaser(AntiRelease *); // expected-error {{no function template matches function template specialization 'templateReleaser'}} + +template<> +void templateReleaser(ExplicitAntiRelease *) {} // expected-error {{no function template matches function template specialization 'templateReleaser'}} + +template<> +void templateReleaser(__attribute__((ns_consumed)) ProRelease *); // no-warning |