[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
MaxEW707 wrote: @shafik @AaronBallman @zmodem I believe I addressed all the feedback. Let me know if I missed anything. Feel free to ping anyone else I may have missed above :). https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/27] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/26] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/25] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/24] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/23] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/22] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/21] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -0,0 +1,87 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -fms-extensions
-fms-compatibility -fms-reference-binding -Wno-microsoft-reference-binding -o -
| FileCheck %s
+
+struct A {};
+struct B : A {};
+
+void fAPickConstRef(A&) {}
+void fAPickConstRef(const A&) {}
+
+void fBPickConstRef(A&) {}
+void fBPickConstRef(const A&) {}
+
+void fAPickRef(A&) {}
+void fAPickRef(const volatile A&) {}
+
+// NOTE: MSVC incorrectly picks the `const volatile A&` overload with the
mangled name
MaxEW707 wrote:
https://godbolt.org/z/GvWY4n7rK
https://developercommunity.visualstudio.com/t/_MSC_VER--1940-MSVC-allows-binding-a/10811594
As noted in the comment this appears to be a bug in MSVC here as it also occurs
during conforming reference binding. For clang we will continue to pick the
`A&` overload when ms non-conforming reference binding is in use.
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/20] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/15] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/14] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From c66fee7969fc4bd8b5ce79085f0fc09cbc4147da Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/13] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c2e0282d1c72d..becf12fa62ec00 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ C23 Feature Support
New Compiler Flags
--
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 0035092ce0d863..ff350410d598a0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -307,6 +307,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28a..53a356d120e3a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3034,6 +3034,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8492,6 +8498,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..6bd575d105675b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10161,6 +10161,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 843d68c85bc592..13867181b21c07 100644
--- a/clang/lib/Driver/Tool
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -7272,6 +7272,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
CmdArgs.push_back("-fdelayed-template-parsing");
}
+ if (Args.hasFlag(options::OPT_fms_reference_binding,
+ options::OPT_fno_ms_reference_binding,
+ IsWindowsMSVC && !HaveCxx20))
MaxEW707 wrote:
I am not quite following. I modelled this flag similar to how we do other ms
flags such as `-fms-extensions` and `-fdelayed-template-parsing`. That is it is
enabled by cl driver options or enabled by default for MSVC targets.
It is still valid for you to explicitly do `-fms-extensions` on non-msvc
targets if you want those behaviours for reasons.
When porting some old MSVC only games to certain console manufacturers it was
common to use `-fms-extensions` and friends to get it building on their vendor
clang :).
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
MaxEW707 wrote: > I'd like to see this change make it into the repo, as I'm in a similar > situation with a 6+ million line codebase. What's the next steps to advance > this? Hey sorry. I've been busy with other work prios and an msvc mangling bug. I still intend to get back to this as I also need it. I plan to get back to it in about 1.5 weeks to address all the feedback. I also want to change it to be opt-in for clang-cl for now since it is the first impl instead of being opt-out like in msvc. I don't want to accidentally break users who are using clang-cl without `/permissive-` especially since it changes overload resolution behaviour. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
RogerSanders wrote: I'd like to see this change make it into the repo, as I'm in a similar situation with a 6+ million line codebase. What's the next steps to advance this? https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -8492,6 +8498,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">, HelpText<"Enable C++ builtin type wchar_t (default)">; def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">, HelpText<"Disable C++ builtin type wchar_t">; +def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">, + HelpText<"Do not accept expressions that bind a non-const lvalue reference to a user-defined type temporary">, zmodem wrote: "(default)" at the end of the help text. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -5821,3 +5821,33 @@ specify the starting offset to begin embedding from. The
resources is treated
as being empty if the specified offset is larger than the number of bytes in
the resource. The offset will be applied *before* any ``limit`` parameters are
applied.
+
+MSVC Extensions
+===
+
+Clang supports a number of extensions inorder to imitate MSVC.
+Some of these extensions are behind ``-fms-compatibility`` and
``-fms-extensions`` which
+are further described in :doc:`MSVCCompatibility`.
+
+MSVC Reference Binding
+--
+
+.. code-block:: c++
+
+ struct A {};
+
+ A& a = A();
+
+Please see the `MSDN doc
+`_
+for more information on this non-conforming C++ extension.
+
+MSVC allows user-defined type temporaries to be bound to non-const lvalue
references when ``/permissive``
+or ``/Zc:referenceBinding-`` are given on the command line.
+
+The current default behavior as of MSVC 1940 is ``/permissive``.
+As of Visual Studio 2017, ``/permissive-`` is the default for projects meaning
C++ conformance is enforced when
+building with MSVC in Visual Studio.
+
+This MSVC extension can be enabled with ``-fms-reference-binding`` with the
clang or cl driver.
+This MSVC extension can be enabled with ``/Zc:referenceBinding-`` with the cl
driver.
zmodem wrote:
Let's s/cl/clang-cl/g. (I think we always refer to it as clang-cl in docs.)
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -950,12 +950,14 @@ static void TranslatePermissive(Arg *A,
llvm::opt::DerivedArgList &DAL,
const OptTable &Opts) {
DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_));
DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names));
+ DAL.AddFlagArg(A, Opts.getOption(options::OPT_fms_reference_binding));
zmodem wrote:
Do we need to check for c++20 like we do above?
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -7272,6 +7272,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
CmdArgs.push_back("-fdelayed-template-parsing");
}
+ if (Args.hasFlag(options::OPT_fms_reference_binding,
+ options::OPT_fno_ms_reference_binding,
+ IsWindowsMSVC && !HaveCxx20))
zmodem wrote:
Could we do something better for the non-windows or c++20 cases?
We could emit a warning saying the flag is unsupported, or we could put those
conditions first so that we don't call hasFlag, which would make clang warn
about the unused option.
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -3034,6 +3034,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, Group, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">, MarshallingInfoFlag>, ImpliedByAnyOf<[fms_compatibility.KeyPath]>; +def fms_reference_binding : Flag<["-"], "fms-reference-binding">, Group, + Visibility<[ClangOption, CC1Option, CLOption]>, + HelpText<"Accept expressions that bind a non-const lvalue reference to a user-defined type temporary as supported by the Microsoft Compiler">, zmodem wrote: s/Compiler/compiler/ I know the file is not consistent, but historically it's been trying to stay within 80 columns, so consider breaking up the HelpText (also below). See e.g. fms_compatibility_version for an example. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/zmodem edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/zmodem commented: Just some nits from my side. (I only looked at the docs and driver code) https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -0,0 +1,151 @@
+// RUN: %clang_cc1 -fsyntax-only -Wno-microsoft-reference-binding -verify
-fms-reference-binding %s
+// RUN: %clang_cc1 -DEXTWARN -fsyntax-only -verify -fms-reference-binding %s
+
+#ifdef EXTWARN
+
+struct A {};
+void fARef(A&) {}
+
+void test1() {
+ A& a1 = A(); // expected-warning{{binding a user-defined type temporary to a
non-const lvalue is a Microsoft extension}}
+
+ fARef(A()); // expected-warning{{binding a user-defined type temporary to a
non-const lvalue is a Microsoft extension}}
+}
+
+void fARefDoNotWarn(A&) {}
+void fARefDoNotWarn(const A&) {}
+
+// expected-note@+2 {{candidate function not viable: 1st argument ('const A')
would lose const qualifier}}
+// expected-note@+1 {{candidate function not viable: 1st argument ('const A')
would lose const qualifier}}
+void fARefLoseConstQualifier(A&) {}
+
+void test2() {
+ // This should not warn since `fARefDoNotWarn(const A&)` is a better
candidate
+ fARefDoNotWarn(A());
+
+ const A a;
+ fARefLoseConstQualifier(a); // expected-error{{no matching function for call
to 'fARefLoseConstQualifier'}}
+ fARefLoseConstQualifier(static_cast(a)); // expected-error{{no
matching function for call to 'fARefLoseConstQualifier'}}
+}
+
+#else
+
+struct A {};
+struct B : A {};
+
+B fB();
+A fA();
+
+A&& fARvalueRef();
+A(&&fARvalueRefArray())[1];
+
+void fARef(A&) {}
+
+// expected-note@+2 {{candidate function not viable: expects an lvalue for 1st
argument}}
+// expected-note@+1 {{candidate function not viable: expects an lvalue for 1st
argument}}
+void fAVolatileRef(volatile A&) {}
+
+void fIntRef(int&) {} // expected-note{{candidate function not viable: expects
an lvalue for 1st argument}}
+void fDoubleRef(double&) {} // expected-note{{candidate function not viable:
expects an lvalue for 1st argument}}
+
+void fIntConstRef(const int&) {}
+void fDoubleConstRef(const double&) {}
+
+void fIntArray(int (&)[1]); // expected-note{{candidate function not viable:
expects an lvalue for 1st argument}}
+void fIntConstArray(const int (&)[1]);
+
+namespace NS {
+ void fARef(A&) {}
+
+ // expected-note@+2 {{passing argument to parameter here}}
+ // expected-note@+1 {{passing argument to parameter here}}
+ void fAVolatileRef(volatile A&) {}
+
+ void fIntRef(int&) {} // expected-note{{passing argument to parameter here}}
+ void fDoubleRef(double&) {} // expected-note{{passing argument to parameter
here}}
+
+ void fIntConstRef(const int&) {}
+ void fDoubleConstRef(const double&) {}
+
+ A(&&fARvalueRefArray())[1];
+
+ void fIntArray(int (&)[1]); // expected-note{{passing argument to parameter
here}}
+
+ void fIntConstArray(const int (&)[1]);
+}
+
+void test1() {
+ double& rd2 = 2.0; // expected-error{{non-const lvalue reference to type
'double' cannot bind to a temporary of type 'double'}}
+ int& i1 = 0; // expected-error{{non-const lvalue reference to type 'int'
cannot bind to a temporary of type 'int'}}
+
+ fIntRef(0); // expected-error{{no matching function for call to 'fIntRef'}}
+ fDoubleRef(0.0); // expected-error{{no matching function for call to
'fDoubleRef'}}
+
+ NS::fIntRef(0); // expected-error{{non-const lvalue reference to type 'int'
cannot bind to a temporary of type 'int'}}
+ NS::fDoubleRef(0.0); // expected-error{{non-const lvalue reference to type
'double' cannot bind to a temporary of type 'double'}}
+
+ int i2 = 2;
+ double& rd3 = i2; // expected-error{{non-const lvalue reference to type
'double' cannot bind to a value of unrelated type 'int'}}
+}
+
+void test2() {
+ fIntConstRef(0);
+ fDoubleConstRef(0.0);
+
+ NS::fIntConstRef(0);
+ NS::fDoubleConstRef(0.0);
+
+ int i = 0;
+ const int ci = 0;
+ volatile int vi = 0;
+ const volatile int cvi = 0;
+ bool b = true;
+
+ const volatile int &cvir1 = b ? ci : vi; // expected-error{{volatile lvalue
reference to type 'const volatile int' cannot bind to a temporary of type
'int'}}
+
+ volatile int& vir1 = 0; // expected-error{{volatile lvalue reference to type
'volatile int' cannot bind to a temporary of type 'int'}}
+ const volatile int& cvir2 = 0; // expected-error{{volatile lvalue reference
to type 'const volatile int' cannot bind to a temporary of type 'int'}}
+}
+
+void test3() {
+ A& a1 = A();
+
+ fARef(A());
+ fARef(static_cast(a1));
+
+ fAVolatileRef(A()); // expected-error{{no matching function for call to
'fAVolatileRef'}}
+ fAVolatileRef(static_cast(a1)); // expected-error{{no matching function
for call to 'fAVolatileRef'}}
+
+ fARef(B());
+
+ NS::fARef(A());
+ NS::fARef(static_cast(a1));
+
+ NS::fAVolatileRef(A()); // expected-error{{volatile lvalue reference to type
'volatile A' cannot bind to a temporary of type 'A'}}
+ NS::fAVolatileRef(static_cast(a1)); // expected-error{{volatile lvalue
reference to type 'volatile A' cannot bind to a temporary of type 'A'}}
+
+ NS::fARef(B());
+
+ A& a2 = fA();
+
+ A& a3 = fARvalueRef();
+
+ const A& rca = fB();
+ A& ra = fB();
+}
+
+void test4() {
+ A (&arr
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -5821,3 +5821,33 @@ specify the starting offset to begin embedding from. The resources is treated as being empty if the specified offset is larger than the number of bytes in the resource. The offset will be applied *before* any ``limit`` parameters are applied. + +MSVC Extensions +=== + +Clang supports a number of extensions inorder to imitate MSVC. AaronBallman wrote: ```suggestion Clang supports a number of extensions in order to imitate MSVC. ``` https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/AaronBallman commented: Thanks, I think this is a good compromise! I did have some additional test coverage, and I'd appreciate additional eyes from @zmodem and @MaskRay, especially regarding the compiler options. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From c66fee7969fc4bd8b5ce79085f0fc09cbc4147da Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/12] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c2e0282d1c72..becf12fa62ec0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ C23 Feature Support
New Compiler Flags
--
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 0035092ce0d86..ff350410d598a 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -307,6 +307,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28..53a356d120e3a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3034,6 +3034,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8492,6 +8498,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..6bd575d105675 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10161,6 +10161,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 843d68c85bc59..13867181b21c0 100644
--- a/clang/lib/Driver/ToolChains/Cla
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -4446,6 +4446,24 @@ CompareStandardConversionSequences(Sema &S,
SourceLocation Loc,
T1 = S.Context.getQualifiedType(UnqualT1, T1Quals);
if (isa(T2) && T2Quals)
T2 = S.Context.getQualifiedType(UnqualT2, T2Quals);
+
+ if (S.getLangOpts().MSVCReferenceBinding &&
+ S.Context.hasSameType(SCS1.getFromType(), SCS2.getFromType()) &&
+ !SCS1.getFromType().hasQualifiers() && SCS1.BindsToRvalue &&
+ SCS2.BindsToRvalue) {
+
+// When binding a user-defined type temporary to an lvalue MSVC will
+// pick `const T&` over `T&` when binding an unqualified `T&&`.
+// Therefore we want to pick the more qualified const overload in this
+// specific case.
MaxEW707 wrote:
https://godbolt.org/z/xaPE6rMc1 for reference on this overload resolution case.
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From c66fee7969fc4bd8b5ce79085f0fc09cbc4147da Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/11] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c2e0282d1c72d..becf12fa62ec00 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ C23 Feature Support
New Compiler Flags
--
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 0035092ce0d863..ff350410d598a0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -307,6 +307,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28a..53a356d120e3a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3034,6 +3034,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8492,6 +8498,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..6bd575d105675b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10161,6 +10161,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 843d68c85bc592..13867181b21c07 100644
--- a/clang/lib/Driver/Tool
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From c66fee7969fc4bd8b5ce79085f0fc09cbc4147da Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/10] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c2e0282d1c72d..becf12fa62ec00 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ C23 Feature Support
New Compiler Flags
--
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 0035092ce0d863..ff350410d598a0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -307,6 +307,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28a..53a356d120e3a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3034,6 +3034,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8492,6 +8498,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..6bd575d105675b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10161,6 +10161,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 843d68c85bc592..13867181b21c07 100644
--- a/clang/lib/Driver/Tool
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
MaxEW707 wrote: > 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. That is a fair point. I did some further digging. Starting with C++20 MSVC starting enforcing various C++ conformance options by default. For example `/permissive-` is the default now meaning `/Zc:referenceBinding` is set. MSVC does not allow its custom reference binding rules by default anymore. Godbolt for reference: https://godbolt.org/z/6hTeGeb6x. We already do similar behaviour in the driver for the `delayed-template-parsing` extension. `delayed-template-parsing`, called `/Zc:twoPhase-` in MSVC driver parlance, is enabled by default if we are windows msvc and not C++20 since MSVC does two-phase lookup by default in C++20 onwards. In this PR I now enable `ms-reference-binding` by default if we are windows msvc and not C++20 as well to imitate MSVC behaviour. `ms-reference-binding` is still an individual controllable option and is also properly set if you use the `/permissive` or `/permissive-` larger group option in the cl driver mode. I wrote up a small gist here about what `-fms-extensions` covers, https://gist.github.com/MaxEW707/3fbb3a223710b6aa9269f7ffbdccbfc9. Most of it are things that you always want if you are targeting msvc which include the implicit `_GUID` struct, calling convention identifiers like `__stdcall`, SEH identifiers like `__finally`, Microsoft pragma support, builtin macros like `_WCHAR_T_DEFINED`, imitating MSVC PP token pasting behaviour, handling ^Z EOF in the lexer, etc. It also includes Microsoft extensions that do not have a conformance mode toggle currently in MSVC such as allowing a static declaration to follow an extern declaration, allowing inline function definitions on pure virtual methods, allowing type definitions inside an anonymous union/struct, etc. Most of these extensions in this category so far are fairly benign and don't alter the language semantics much compared to two-phase lookup or reference binding for example. Let me know if this is a satisfactory compromise :). I think it models what seems to be the precedent especially around two-phase lookup. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From e0528ecc441e33822426b8b3d6522d056c95bb54 Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 1/7] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4638b91b48f95..567effa83f845 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,6 +486,10 @@ New Compiler Flags
- ``-fpointer-tbaa`` enables emission of distinct type-based alias
analysis tags for incompatible pointers.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index a6f36b23f07dc..188cea2c900c7 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -306,6 +306,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 8707e71f2a319..cd568c9f8f60f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3036,6 +3036,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8467,6 +8473,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d638d31e050dc..34ea43c3fa2e2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10158,6 +10158,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 71cd
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From e0528ecc441e33822426b8b3d6522d056c95bb54 Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 1/6] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4638b91b48f95..567effa83f845 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,6 +486,10 @@ New Compiler Flags
- ``-fpointer-tbaa`` enables emission of distinct type-based alias
analysis tags for incompatible pointers.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index a6f36b23f07dc..188cea2c900c7 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -306,6 +306,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 8707e71f2a319..cd568c9f8f60f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3036,6 +3036,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8467,6 +8473,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d638d31e050dc..34ea43c3fa2e2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10158,6 +10158,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 71cd
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 updated
https://github.com/llvm/llvm-project/pull/99833
>From e0528ecc441e33822426b8b3d6522d056c95bb54 Mon Sep 17 00:00:00 2001
From: MaxEW707
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 1/5] Support MSVC lvalue to temporary reference binding
---
clang/docs/ReleaseNotes.rst | 4 +
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Driver/Options.td | 12 +++
clang/include/clang/Sema/Sema.h | 2 +
clang/lib/Driver/ToolChains/Clang.cpp | 5 +
clang/lib/Driver/ToolChains/MSVC.cpp| 1 +
clang/lib/Sema/SemaInit.cpp | 22 +++--
clang/lib/Sema/SemaOverload.cpp | 16 ++-
clang/test/Driver/cl-permissive.c | 7 ++
clang/test/Driver/cl-zc.cpp | 2 +
clang/test/SemaCXX/ms-reference-binding.cpp | 102
11 files changed, 165 insertions(+), 9 deletions(-)
create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4638b91b48f95..567effa83f845 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,6 +486,10 @@ New Compiler Flags
- ``-fpointer-tbaa`` enables emission of distinct type-based alias
analysis tags for incompatible pointers.
+- ``-fms-reference-binding`` and its clang-cl counterpart
``/Zc:referenceBinding``.
+ Implements the MSVC extension where expressions that bind a user-defined
type temporary
+ to a non-const lvalue reference are allowed.
+
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index a6f36b23f07dc..188cea2c900c7 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -306,6 +306,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations
/ deallocations with
LANGOPT(OpenACC , 1, 0, "OpenACC Enabled")
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const
lvalue reference to a temporary")
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are
unavailable")
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 8707e71f2a319..cd568c9f8f60f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3036,6 +3036,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">,
Group,
+ Visibility<[ClangOption, CC1Option, CLOption]>,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary as supported by the Microsoft Compiler">,
+ MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">,
Group,
+ Visibility<[ClangOption, CLOption]>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
@@ -8467,6 +8473,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
HelpText<"Enable C++ builtin type wchar_t (default)">;
def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+ HelpText<"Do not accept expressions that bind a non-const lvalue reference
to a user-defined type temporary">,
+ Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+ HelpText<"Accept expressions that bind a non-const lvalue reference to a
user-defined type temporary">,
+ Alias;
def _SLASH_Z7 : CLFlag<"Z7">, Alias,
HelpText<"Enable CodeView debug information in object files">;
def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d638d31e050dc..34ea43c3fa2e2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10158,6 +10158,8 @@ class Sema final : public SemaBase {
CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
+ bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
/// AddOverloadCandidate - Adds the given function to the set of
/// candidate functions, using the given function call arguments. If
/// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 71cd
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
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 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
MaxEW707 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. 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. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/AaronBallman requested changes to this pull request. Thank you for this! I think there's some work left to be done though. 1) Please add an extension warning (and tests for it) so users know where the extension is being used even if they opt into it explicitly. This is important for `-pedantic` mode. 2) 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 3) Please document the extension in `clang/docs/LanguageExtensions.rst` https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/shafik commented: I would like @AaronBallman to review this before committing. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
@@ -5138,7 +5148,11 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
// -- Otherwise, the reference shall be an lvalue reference to a
//non-volatile const type (i.e., cv1 shall be const), or the
reference
//shall be an rvalue reference.
- if (!isRValRef && (!T1.isConstQualified() || T1.isVolatileQualified())) {
+ const bool CanBindLValueRef =
rnk wrote:
This boolean isn't needed if `!isRValRef`. Can you structure it as:
```
if (!isRValRef) {
bool CanBindLValueRef = ...
if (!CanBindLValueRef) {
}
}
```
... or whatever is most readable, I just want to reduce the scope of the
variable and avoid extra LangOpt checks.
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/rnk edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/rnk approved this pull request. I think this looks good, but I would appreciate another reviewer looking at the patch. https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/99833 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Max Winkler (MaxEW707) Changes MSDN docs for reference: https://learn.microsoft.com/en-us/cpp/build/reference/zc-referencebinding-enforce-reference-binding-rules?view=msvc-170 The warning referenced in that MSDN article: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4239?view=msvc-170 MSVC has an extension, that has been enabled by default until very recently when MSVC started their C++ conformance trend, that allows binding a user-defined type temporary to a non-const lvalue. When trying to port over various large internal windows only tools this became hard as they rely heavily on this extension. While I am not a fan of this extension changing our code to remove uses of it is quite hard do to how the code is structured. The end goal is to longer rely on this extension but at this moment in time it is less bug prone to have clang support this extension and focus on removal sometime in the future after porting to clang. >From the MSDN reference abive I did not implement the warning at level 4, >C4239, since everyone disables said warning who requires this extension so I >felt it wasn't worth the effort. Implement the MSVC extension is the main >requirement. Enable this new option with `/permissive` since `/permissive` enables this MSVC extension. --- Full diff: https://github.com/llvm/llvm-project/pull/99833.diff 11 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+4) - (modified) clang/include/clang/Basic/LangOptions.def (+1) - (modified) clang/include/clang/Driver/Options.td (+12) - (modified) clang/include/clang/Sema/Sema.h (+2) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+5) - (modified) clang/lib/Driver/ToolChains/MSVC.cpp (+1) - (modified) clang/lib/Sema/SemaInit.cpp (+14-8) - (modified) clang/lib/Sema/SemaOverload.cpp (+15-1) - (modified) clang/test/Driver/cl-permissive.c (+7) - (modified) clang/test/Driver/cl-zc.cpp (+2) - (added) clang/test/SemaCXX/ms-reference-binding.cpp (+102) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4638b91b48f95..567effa83f845 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -486,6 +486,10 @@ New Compiler Flags - ``-fpointer-tbaa`` enables emission of distinct type-based alias analysis tags for incompatible pointers. +- ``-fms-reference-binding`` and its clang-cl counterpart ``/Zc:referenceBinding``. + Implements the MSVC extension where expressions that bind a user-defined type temporary + to a non-const lvalue reference are allowed. + Deprecated Compiler Flags - diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index a6f36b23f07dc..ac4cabb9a82c7 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -306,6 +306,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations / deallocations with LANGOPT(OpenACC , 1, 0, "OpenACC Enabled") LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with '-fms-compatibility'") +LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const lvalue reference to a user-defined type temporary") LANGOPT(SizedDeallocation , 1, 0, "sized deallocation") LANGOPT(AlignedAllocation , 1, 0, "aligned allocation") LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are unavailable") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 8707e71f2a319..cd568c9f8f60f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3036,6 +3036,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, Group, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">, MarshallingInfoFlag>, ImpliedByAnyOf<[fms_compatibility.KeyPath]>; +def fms_reference_binding : Flag<["-"], "fms-reference-binding">, Group, + Visibility<[ClangOption, CC1Option, CLOption]>, + HelpText<"Accept expressions that bind a non-const lvalue reference to a user-defined type temporary as supported by the Microsoft Compiler">, + MarshallingInfoFlag>; +def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">, Group, + Visibility<[ClangOption, CLOption]>; defm asm_blocks : BoolFOption<"asm-blocks", LangOpts<"AsmBlocks">, Default, PosFlag, @@ -8467,6 +8473,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">, HelpText<"Enable C++ builtin type wchar_t (default)">; def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">, HelpText<"Disable C++ builtin type wchar_t">; +def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">, + HelpText<"Do not accept expressions that bind a non-const lvalue reference to a user-defined type temporary"
[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)
https://github.com/MaxEW707 created https://github.com/llvm/llvm-project/pull/99833 MSDN docs for reference: https://learn.microsoft.com/en-us/cpp/build/reference/zc-referencebinding-enforce-reference-binding-rules?view=msvc-170 The warning referenced in that MSDN article: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4239?view=msvc-170 MSVC has an extension, that has been enabled by default until very recently when MSVC started their C++ conformance trend, that allows binding a user-defined type temporary to a non-const lvalue. When trying to port over various large internal windows only tools this became hard as they rely heavily on this extension. While I am not a fan of this extension changing our code to remove uses of it is quite hard do to how the code is structured. The end goal is to longer rely on this extension but at this moment in time it is less bug prone to have clang support this extension and focus on removal sometime in the future after porting to clang. >From the MSDN reference abive I did not implement the warning at level 4, >C4239, since everyone disables said warning who requires this extension so I >felt it wasn't worth the effort. Implement the MSVC extension is the main >requirement. Enable this new option with `/permissive` since `/permissive` enables this MSVC extension. >From e0528ecc441e33822426b8b3d6522d056c95bb54 Mon Sep 17 00:00:00 2001 From: MaxEW707 Date: Fri, 21 Jun 2024 20:37:40 -0700 Subject: [PATCH 1/2] Support MSVC lvalue to temporary reference binding --- clang/docs/ReleaseNotes.rst | 4 + clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Driver/Options.td | 12 +++ clang/include/clang/Sema/Sema.h | 2 + clang/lib/Driver/ToolChains/Clang.cpp | 5 + clang/lib/Driver/ToolChains/MSVC.cpp| 1 + clang/lib/Sema/SemaInit.cpp | 22 +++-- clang/lib/Sema/SemaOverload.cpp | 16 ++- clang/test/Driver/cl-permissive.c | 7 ++ clang/test/Driver/cl-zc.cpp | 2 + clang/test/SemaCXX/ms-reference-binding.cpp | 102 11 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4638b91b48f95..567effa83f845 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -486,6 +486,10 @@ New Compiler Flags - ``-fpointer-tbaa`` enables emission of distinct type-based alias analysis tags for incompatible pointers. +- ``-fms-reference-binding`` and its clang-cl counterpart ``/Zc:referenceBinding``. + Implements the MSVC extension where expressions that bind a user-defined type temporary + to a non-const lvalue reference are allowed. + Deprecated Compiler Flags - diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index a6f36b23f07dc..188cea2c900c7 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -306,6 +306,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations / deallocations with LANGOPT(OpenACC , 1, 0, "OpenACC Enabled") LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with '-fms-compatibility'") +LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const lvalue reference to a temporary") LANGOPT(SizedDeallocation , 1, 0, "sized deallocation") LANGOPT(AlignedAllocation , 1, 0, "aligned allocation") LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are unavailable") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 8707e71f2a319..cd568c9f8f60f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3036,6 +3036,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, Group, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">, MarshallingInfoFlag>, ImpliedByAnyOf<[fms_compatibility.KeyPath]>; +def fms_reference_binding : Flag<["-"], "fms-reference-binding">, Group, + Visibility<[ClangOption, CC1Option, CLOption]>, + HelpText<"Accept expressions that bind a non-const lvalue reference to a user-defined type temporary as supported by the Microsoft Compiler">, + MarshallingInfoFlag>; +def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">, Group, + Visibility<[ClangOption, CLOption]>; defm asm_blocks : BoolFOption<"asm-blocks", LangOpts<"AsmBlocks">, Default, PosFlag, @@ -8467,6 +8473,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">, HelpText<"Enable C++ builtin type wchar_t (default)">; def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">, HelpText<"Disable C++ builtin type wchar_t">; +de
