[SR-11373] Don't perform X-to-pointer conversions for generic params inferred to be pointer types #53774
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
type checker
Area → compiler: Semantic analysis
Environment
Swift version 5.1-dev (LLVM c5340df2d1, Swift 98a54a1)
Target: x86_64-apple-darwin18.5.0
Additional Detail from JIRA
md5: 13080b3b09be239733bd1a724a240c24
Issue Description:
Came up with the following bit of cursed Swift this morning:
This happens because
min
's generic parameter T gets inferred to be an UnsafePointer, resulting in string-to-pointer conversions for its arguments (and the first arg just happens to have a lower address). It then leads to undefined behaviour frommin
returning a now dangling pointer.Arguably we should ban X-to-pointer conversions for generic parameters that happen to be inferred as pointer types, such as the following:
I don't know how source breaking such a change would be though. The two examples given above are undefined behaviour, but it could be possible that somebody is using this mechanic in a well-defined manner (I can't think of any particularly motivating examples off the top of my head though). Would such a change require an SE proposal?
The text was updated successfully, but these errors were encountered: