-
Notifications
You must be signed in to change notification settings - Fork 593
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
hb-algs.hh(352) : warning C4172: returning address of local variable or temporary #2293
Comments
I'll be damned. Let me see if I can figure out how this can be fixed... I wonder if it's wrong to forward same argument twice to begin with... At any rate, I don't understand how auto can decide to return an lvalue when the statement is rvalue. Basically what I'm saying is with Would love to see someone who knows better chime in. |
Also, unless you get same warning with their latest compiler, I'd just ignore this. |
I actually did get this warning with the latest and greatest MS Visual Studio 2017 (Version 15.9.21). I actually updated my Visual Studio a few days ago specifically because of this warning (I wanted to see it this is perhaps a compiler bug). But the warning remains... As I said, I don't really understand what this code does. Hopefully somebody can chime in. Or if you are confident this is a compiler bug, so be it... |
Happens with VS2017 https://ci.appveyor.com/project/harfbuzz/harfbuzz/builds/31899255/job/2q148ic0mjvld8c5#L1478 and VS2019 https://ci.appveyor.com/project/harfbuzz/harfbuzz/builds/31899255/job/5304e8ijxhheyi0x#L1502 and apparently the check weren't implemented in VS2015. |
If you can get some sort of minimal repro for the bug, I'm happy to pass it on to the VC++ team; would be nice to see this cleaned up. Also, you might want to edit that snippet back to something like |
That's super helpful. Thanks. |
A friend spotted the issue: you have excessive parens around the return, which means it's returning a reference. You might just have the warning disabled on other compilers? See https://godbolt.org/z/PqEbdK Edit: nvm, see below |
Oof. That' brutal! THANK YOU! I'll see what to do with it. |
Hi, I'm the friend. In this case it will happen even if you remove the parens. It could also happen if you left the parens and removed other stuff. Here's another simplified case where it will be wrong: https://godbolt.org/z/aWxbWo Update: actually, we aren't entirely sure what's going on with MSVC. Update 2: more information in the next comment. |
There are two problems, I think:
There is a subtle issue. Take Another perspective:
An rvalue reference is still a mutable reference that may appear on the left hand side of an assignment. |
The first part has been fixed, pending a release. |
Oh, forgot to update again. First issue: https://developercommunity.visualstudio.com/content/problem/1225750/msvc-calculates-lifetime-for-temporary-incorrectly.html This is pending a public release with the fix. Second issue: https://developercommunity.visualstudio.com/content/problem/1225892/msvc-incorrectly-detects-return-type-with-template.html The fix here is to pass |
I inspected that:
I believe the parens are expected.
Fixed this.
True. I prefer to write our generic algorithms as generics though. That said, we're getting to a point that I like to just start using Anyway. Anything else I need to be fixing here, @ihameed @randrew @CoffeeFlux ? |
Well, it seems fine to me. But, I guessed the original cause incorrectly, anyway, so what do I know :) I hadn't expected the ternary compatibility thing to affect a return type. I had thought it only affected compilations being accepted or rejected. The comments from the MSFT engineers hint they will update the documentation to reflect that. |
Is there any way to turn on/off pragmas from within the code to get the correct behavior? |
I think you can just enable |
Anyone who likes to try adding that to any of our build systems please do so. |
16.9 has been promoted to stable, which includes the lifetime fix: https://developercommunity2.visualstudio.com/t/msvc-calculates-lifetime-for-temporary-incorrectly/1225750 |
When compiling the latest HarfBuzz (2.6.4) MS Visual C++ 15 gives the following 3 warnings:
The relevant code snippet is below. Lines 352, 359 and 366 are in bold:
However, I do not understand what this code does.
Is this a known warning? It doesn't look like it should be ignored -- returning an address of a local variable or temporary probably results in undefined behaviour. Not sure...
The text was updated successfully, but these errors were encountered: