[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 29 07:07:47 PDT 2024


AaronBallman wrote:

> > This should be controllable via -fms-extensions/-fno-ms-extensions; having its own dialect flag is a bit novel but I'm not strongly opposed. CC @MaskRay @jansvoboda11 for driver/options opinions
> 
> For this feedback I intentionally didn't do this because this ms extension isn't one intended to be always enabled. -fms-extensions enables extensions that are always valid to use with msvc such as the `__try` and `__finally` keywords for SEH.

That's kind of the crux of this -- `-fms-extensions` enables Microsoft extensions, and this is a Microsoft extension. Our documentation is pretty quiet about what it means to "enable Microsoft extensions": https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions

> MSVC allows controlling this option independently here, [/Zc:ReferenceBinding](https://learn.microsoft.com/en-us/cpp/build/reference/zc-referencebinding-enforce-reference-binding-rules?view=msvc-170). MSVC `/permissive-` disables this reference binding extension, however `__try` and friends are still available as they are vital for operating within a Win32 environment. Newer C++ modes like C++20 also implicitly disable this reference binding extension in MSVC as they move towards proper C++ conformance by default.
> 
> This is a one off extension similar to -fms-volatile or -fms-define-stdc. I would like to keep it a separate option that can be individually controlled instead of grouping it with -fms-extensions.

Oh, I think it should still be individually controlled via its own flag. The scenario I am thinking about is when the user passed `-fms-extensions` and no other individual flags. I think that mode should enable all of the Microsoft extensions. Then users can opt out of whatever extensions they don't want to enable. But I think it's confusing if `-fms-extensions` still requires the user to explicitly opt in to other Microsoft-specific extensions. CC @zmodem @rnk for additional opinions.


https://github.com/llvm/llvm-project/pull/99833


More information about the cfe-commits mailing list