Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around conditional operator bugs #729

Open
kyleheadley opened this issue Oct 18, 2021 · 1 comment
Open

Work around conditional operator bugs #729

kyleheadley opened this issue Oct 18, 2021 · 1 comment

Comments

@kyleheadley
Copy link
Member

The compiler doesn't handle the ? : operator as well as we'd like, for example, from icecast:

client.c:192:34: error: passing 'char *' to parameter of incompatible type '_Nt_array_ptr<const char>'
                                 plain ? "text/plain" : "text/html", "utf-8",
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This has been noted in the microsoft repo. However, their priority is low and they might not get to it in our time frame.

a concrete example is:

void takes_string(_Nt_array_ptr<char> s) {}
void test() {
  takes_string(0 ? "true" : "false");
}

this doesn't compile, but will if you pass a simple string rather than with the operator. (Or it will complain about bounds if test is _Checked).

I've seen this string version in icecast and libarchive, I'll note below if there are any other variants.

@john-h-kastner
Copy link
Collaborator

john-h-kastner commented Oct 19, 2021

Unfortunately, adding a C-Stlye cast is not sufficient to workaround this error. An _Assume_bounds_cast does work, but we can't cast to bounds(unknown) without a different bounds error.

void takes_string(_Nt_array_ptr<char> s) {}
void test() {
  takes_string(_Assume_bounds_cast<_Nt_array_ptr<char>>(0 ? "true" : "false", count(0)));
}

Regarding other variants: this is currently the only error blocking the libtiff build without -alltypes.

libtiff/tif_getimage.c:2613:13: error: cannot guarantee operand of cast to checked function pointer type '_Ptr<int (TIFFRGBAImage * : itype(_Ptr<TIFFRGBAImage>), uint32 * : itype(_Ptr<uint32>), uint32, uint32)>' (aka '_Ptr<int (struct _TIFFRGBAImage * : itype(_Ptr<TIFFRGBAImage>), unsigned int * : itype(_Ptr<uint32>), unsigned int, unsigned int)>') is a function pointer
        img->get = TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libtiff/tif_getimage.c:2768:13: error: cannot guarantee operand of cast to checked function pointer type '_Ptr<int (TIFFRGBAImage * : itype(_Ptr<TIFFRGBAImage>), uint32 * : itype(_Ptr<uint32>), uint32, uint32)>' (aka '_Ptr<int (struct _TIFFRGBAImage * : itype(_Ptr<TIFFRGBAImage>), unsigned int * : itype(_Ptr<uint32>), unsigned int, unsigned int)>') is a function pointer
        img->get = TIFFIsTiled(img->tif) ? gtTileSeparate : gtStripSeparate;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants