Why we need `__attribute__((sentinel(0,1)))`?


(哀殿) #1

Hello Swift community,

I found `__attribute__((sentinel(0,1)))` at https://github.com/apple/swift-clang/blob/c52d85ede49adaec457400697b1d4c1b7ea12881/test/Analysis/variadic-method-types.m#L46.

But I can't imagine how different it is from the `__attribute__((sentinel))`.

So,why we need `__attribute__((sentinel(0,1)))`?
Thanks.


(Greg Parker) #2

This is unrelated to Swift. That file is in clang; it's a test of clang's static analyzer.

__attribute__((sentinel)) is identical to __attribute__((sentinel(0, 0))). The difference between sentinel(n, 0) and sentinel(n, 1) has to do with the handling of the last named parameter before the variadic arguments.
(n, 0) means the last named parameter is not part of the null-terminated list; the required sentinel must come after the last named parameter.
(n, 1) means the last named parameter is part of the null-terminated list; passing null to the last named parameter will satisfy -Wsentinel.
n is the number of non-null arguments that must follow the null sentinel. This is used for functions like execle() which passes envp after the null at the end of argv.

···

On Sep 6, 2016, at 6:50 PM, 哀殿 via swift-users <swift-users@swift.org> wrote:

Hello Swift community,

I found `__attribute__((sentinel(0,1)))` at https://github.com/apple/swift-clang/blob/c52d85ede49adaec457400697b1d4c1b7ea12881/test/Analysis/variadic-method-types.m#L46.

But I can't imagine how different it is from the `__attribute__((sentinel))`.

So,why we need `__attribute__((sentinel(0,1)))`?

--
Greg Parker gparker@apple.com <mailto:gparker@apple.com> Runtime Wrangler