[llvm-branch-commits] [cfe-branch] r322641 - Merging r322236:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 17 04:56:35 PST 2018
Author: hans
Date: Wed Jan 17 04:56:35 2018
New Revision: 322641
URL: http://llvm.org/viewvc/llvm-project?rev=322641&view=rev
Log:
Merging r322236:
------------------------------------------------------------------------
r322236 | rsmith | 2018-01-10 15:08:26 -0800 (Wed, 10 Jan 2018) | 3 lines
In C++17, when instantiating an out-of-line definition of an inline static data
member, don't forget to instantiate the initializer too.
------------------------------------------------------------------------
Modified:
cfe/branches/release_60/ (props changed)
cfe/branches/release_60/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/branches/release_60/test/CodeGenCXX/cxx1z-inline-variables.cpp
cfe/branches/release_60/test/SemaTemplate/cxx17-inline-variables.cpp
Propchange: cfe/branches/release_60/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 17 04:56:35 2018
@@ -1,4 +1,4 @@
/cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:321754,321771,321933,322018,322350,322405,322420,322518,322593
+/cfe/trunk:321754,321771,321933,322018,322236,322350,322405,322420,322518,322593
/cfe/trunk/test:170344
/cfe/trunk/test/SemaTemplate:126920
Modified: cfe/branches/release_60/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=322641&r1=322640&r2=322641&view=diff
==============================================================================
--- cfe/branches/release_60/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/branches/release_60/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Jan 17 04:56:35 2018
@@ -4160,7 +4160,8 @@ void Sema::BuildVariableInstantiation(
// it right away if the type contains 'auto'.
if ((!isa<VarTemplateSpecializationDecl>(NewVar) &&
!InstantiatingVarTemplate &&
- !(OldVar->isInline() && OldVar->isThisDeclarationADefinition())) ||
+ !(OldVar->isInline() && OldVar->isThisDeclarationADefinition() &&
+ !NewVar->isThisDeclarationADefinition())) ||
NewVar->getType()->isUndeducedType())
InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs);
Modified: cfe/branches/release_60/test/CodeGenCXX/cxx1z-inline-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/test/CodeGenCXX/cxx1z-inline-variables.cpp?rev=322641&r1=322640&r2=322641&view=diff
==============================================================================
--- cfe/branches/release_60/test/CodeGenCXX/cxx1z-inline-variables.cpp (original)
+++ cfe/branches/release_60/test/CodeGenCXX/cxx1z-inline-variables.cpp Wed Jan 17 04:56:35 2018
@@ -58,14 +58,22 @@ template<typename T> struct X {
static int a;
static inline int b;
static int c;
+ static const int d;
+ static int e;
};
// CHECK: @_ZN1XIiE1aE = linkonce_odr global i32 10
// CHECK: @_ZN1XIiE1bE = global i32 20
// CHECK-NOT: @_ZN1XIiE1cE
+// CHECK: @_ZN1XIiE1dE = linkonce_odr constant i32 40
+// CHECK: @_ZN1XIiE1eE = linkonce_odr global i32 50
template<> inline int X<int>::a = 10;
int &use3 = X<int>::a;
template<> int X<int>::b = 20;
template<> inline int X<int>::c = 30;
+template<typename T> constexpr int X<T>::d = 40;
+template<typename T> inline int X<T>::e = 50;
+const int *use_x_int_d = &X<int>::d;
+const int *use_x_int_e = &X<int>::e;
template<typename T> struct Y;
template<> struct Y<int> {
Modified: cfe/branches/release_60/test/SemaTemplate/cxx17-inline-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/test/SemaTemplate/cxx17-inline-variables.cpp?rev=322641&r1=322640&r2=322641&view=diff
==============================================================================
--- cfe/branches/release_60/test/SemaTemplate/cxx17-inline-variables.cpp (original)
+++ cfe/branches/release_60/test/SemaTemplate/cxx17-inline-variables.cpp Wed Jan 17 04:56:35 2018
@@ -16,3 +16,14 @@ namespace CompleteType {
constexpr int n = X<true>::value;
}
+
+template <typename T> struct A {
+ static const int n;
+ static const int m;
+ constexpr int f() { return n; }
+ constexpr int g() { return n; }
+};
+template <typename T> constexpr int A<T>::n = sizeof(A) + sizeof(T);
+template <typename T> inline constexpr int A<T>::m = sizeof(A) + sizeof(T);
+static_assert(A<int>().f() == 5);
+static_assert(A<int>().g() == 5);
More information about the llvm-branch-commits
mailing list