From 16d12847c1b43cbea908f6defef0be434e71d7f6 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 4 Sep 2019 08:19:30 +0000 Subject: Re-commit r363191 "[MS] Pretend constexpr variable template specializations are inline" While the next Visual Studio update (16.3) will fix this issue, that hasn't shipped yet. Until then Clang wouldn't work with MSVC's headers which seems unfortunate. Let's keep this in until VS 16.3 ships. (See also PR42843.) > Fixes link errors with clang and the latest Visual C++ 14.21.27702 > headers, which was reported as PR42027. > > I chose to intentionally make these things linkonce_odr, i.e. > discardable, so that we don't emit definitions of these things in every > translation unit that includes STL headers. > > Note that this is *not* what MSVC does: MSVC has not yet implemented C++ > DR2387, so they emit fully specialized constexpr variable templates with > static / internal linkage. > > Reviewers: rsmith > > Differential Revision: https://reviews.llvm.org/D63175 llvm-svn: 370850 --- clang/test/CodeGenCXX/ms-constexpr-var-template.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 clang/test/CodeGenCXX/ms-constexpr-var-template.cpp (limited to 'clang/test') diff --git a/clang/test/CodeGenCXX/ms-constexpr-var-template.cpp b/clang/test/CodeGenCXX/ms-constexpr-var-template.cpp new file mode 100644 index 00000000000..a40f7aacac0 --- /dev/null +++ b/clang/test/CodeGenCXX/ms-constexpr-var-template.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm -triple=x86_64-windows-msvc -fms-compatibility %s -o - | FileCheck %s + +template constexpr bool _Is_integer = false; +template <> constexpr bool _Is_integer = true; +template <> constexpr bool _Is_integer = false; +extern "C" const bool *escape = &_Is_integer; + +// CHECK: @"??$_Is_integer@H@@3_NB" = linkonce_odr dso_local constant i8 1, comdat, align 1 +// Should not emit _Is_integer, since it's not referenced. +// CHECK-NOT: @"??$_Is_integer@D@@3_NB" +// CHECK: @escape = dso_local global i8* @"??$_Is_integer@H@@3_NB", align 8 -- cgit v1.2.3