Warning C28302
For C++ reference-parameter 'parameter_name', an extra
_Deref_
operator was found on 'annotation'.
This warning is reported when an extra level of _Deref_
is used on a parameter of a reference type such as T &a
. A common mistake when using SAL1 annotations is to use __deref
on a reference type. Reference types are understood by SAL, so all annotations are already applied to the underlying type. It's typically not an issue in SAL2 because the free-floating __deref
annotation was removed. If you intend to apply an annotation to a subtype, then you should instead use the SAL2 _AT_
or _Outref_
annotations.
Example
// Oops, trying to apply __elem_writableTo to the pointer being referenced
void f( __deref __elem_writableTo(size) int *& buffer, int size);
void func()
{
int buffer[100] = {};
int *pbuffer = buffer;
f(pbuffer, 100);
}
To address the issue, update to SAL2 annotations:
// Fix warning by switching to SAL2 syntax which has annotations that better describe what the function does.
void f( _Outref_result_buffer_(size) int *& buffer);